1

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!

5 Answers 5

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for bringing this up. How, though, would I emulate uploading a picture through the console?? This is the part that is confusing me. With php, I just find the view that is being executed, and print_r. Then load the page, upload images, and look at the vars. Can you quickly walk me through how to 1.emulate the photo upload, then 2. examine variables. Again, step 1 is the confusing part for me. Thanks!
@Chris: for something like that, logging.debug() is the way to go; depending on your web framework, print probably won't send anything to the response to the browser (and if it does, it might not do it in a useful way; often you end up accidentally writing to the HTTP headers)
0

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).

Comments

0

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

1 Comment

I know how to use a debugger :P. I am just thoroughly confused as to how to test a web page using a python command prompt. See my first response to wooble's answer as to what is confusing. Thanks for your input!
0

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.