开发者

Experienced Python programmers (ESPECIALLY former php programmers) : How do I debug python?

In PHP, it was extremely easy to start开发者_运维百科 hacking away and figuring out what was going on on a page. Just throw in a bunch of echos and print_r's and that was about it. It appears that this technique is not working for me in python. I am getting practice by hacking around in a python photo upload module, and when a photo is uploaded, it creates 3 different size photos. I found the code that does this, but I want to see the state at that particular moment. I tried doing a "print" on the size variable, but it did not show up in my browser.

I guess a more straightforward question would be, is it "pythonic" do debug using the browser ( equivalent to echo's and print_r's in php ), or is this what the python console is for? Thanks!


Use the logging module rather than printing stuff to stdout.

Using the interpreter in interactive mode is a great way to try out code, and pdb is very useful for real debugging.


It's "pythonic" to do debugging using the pdb module.

But really, if you're just "hacking around", then I suggest messing around with an interactive interpreter interface, especially one that supports autocompletion (Python itself comes with IDLE right out of the box).


You need to learn how to use a debugger ;) Hacking with prints is cool for simple php, but you can save a lot of time in higher languages with a debugger.

As mentioned, PDP is a place to start http://docs.python.org/library/pdb.html


As others have mentioned PDB, I'll take the opportunity to sing the praises of Eclipse using the pydev plugin, which is absolutely fantastic. IDLE is also well worth a go. Both of these IDEs allow you to step through code, inspect variables, auto-complete, etc. etc.

http://pydev.org/

Download Eclipse then use the Software Updates menu to add in PyDev.

http://pydev.org/updates


PyCharm from JetBrains is as good as all their other products. It has an integrated debugger and lots more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜