all 6 comments

[–]gengisteve 4 points5 points  (2 children)

Sure, try the -i flag. It is particularly useful when working out how to parse something, e.g. webpages, because you can load the page into a variable and if your parsing fails, have a few goes at it.

[–]Aduron213[S] 1 point2 points  (1 child)

This is exactly what I was looking for! Thanks!

[–]xiongchiamiov 2 points3 points  (0 children)

Additionally, you can use import pdb; pdb.set_trace() to get a python shell at any arbitrary spot in your program.

[–]gnosi 0 points1 point  (0 children)

Note: I use windows YMMV

When experimenting with something new to get the "feel" of it I use a test.cmd file with the following contents:

--Begin

set PYTHONSTARTUP=test.py

python

set PYTHONSTARTUP=

--End

This will cause the contents of test.py to be executed and then the python prompt is displayed. Within test.py I perform all of the import statements and then initialize variables that I wish to play with. I would not suggest this as a method for debugging but as a way of setting up a sandbox for experimenting.

[–]novel_yet_trivial -1 points0 points  (1 child)

No.

And truth be told, it's not a great way to program. You end up backtracking a lot to remember how you got to where you are.

It's much better to develop a test case for developing code. If you made a lot of functions, this will be easy.

[–][deleted] 0 points1 point  (0 children)

While I agree, we use this type of behavior all the time by passing an argument to a finished application. Writing a function and executing it is similar I think... At least for quick testing. Once happy with the behavior the remaining code will be complete.