Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where will Python be logging errors for me (moving from PHP)

I am a PHPer new to Python (2.7 on Win32) and I would like to know where Python is shoving any errors it finds?

Do I need to turn something on, if so where do I do that?

Or, is the idea that you develop using a shell and watch errors spat out via that?

Please share any other good Python debugging/sanity-saving mechanisms you wish you'd known about earlier - or if you have switched from PHP perhaps you can tell me what the Python equivalents of :

ini_set('error_reporting', 1);
display_errors();
trigger_error();
var_dump();

Try and Exceptions looks fairly similar.

I will probably stumble across these answers myself in time, but in the meantime this issue is bugging me (no pun intended).

Thanks a lot.

like image 933
Cups Avatar asked Jan 17 '26 01:01

Cups


1 Answers

Python development is normally done in a shell, and you get a full traceback printed out on any uncaught exception.

If you want to log errors to file, have a look at the logging module. You can either catch exceptions directly, or override the sys.excepthook function which is called for an uncaught error. If you're using a framework for e.g. web development, it may have mechanisms to do this sort of thing already.

like image 54
Thomas K Avatar answered Jan 19 '26 15:01

Thomas K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!