noob: running and testing a file with classes

24 views
Skip to first unread message

psoriasis

unread,
May 24, 2013, 1:49:09 AM5/24/13
to Winpdb
So, I have a file with a class def and I want to test it. My thought
was that, like in the interpreter, I could define the classes by
running the file and then, after perhaps setting a breakpoint in the
classes __init__, use the console to execute a statement that created
an instance of the class (which then would put me at my breakpoint).
see "*" at the end

However, if I "run" it just executes the whole file and it doesn't
seem to establish the class definition (as it would if I was in an
interpreter). I say this because if after I run I go to the console
and exec the create of an instance of the class it doesn't seem to
know what I'm talking about.

I gather that I could alter the file so that the last line in the file
creates the instance and so when I run the file (in winpbd of course)
it would hit that line and I could test but I'd much rather be able to
do stuff like that on the fly vs having to alter the file I'm testing
not to mention that, from what I can tell, I would need to alter the
file elsewhere as winpdb's source window is read-only

*
let's say the file had the class def below (as the entire contents of
the file I've loaded into winpdb) and I want to test the "__init__"
function. Let's say I set a breakpoint at 'print "hi mom"
What would I do in winpdb to get to the breakpoint at the 'print "hi
mom" ' statement (which I imagine means creating an instance of cFred
which requires a statement not in the file)

class cFred:
def __init__(self):
print "hi mom"


Bluebird

unread,
May 24, 2013, 4:47:57 PM5/24/13
to win...@googlegroups.com
Your question is a generic python beginner question and not really related to winpdb. I suggest that you ask it on comp.land.python to receive a more informative answer.

Winpdb is a debugger that does not let you modify code while you execute it, and provides a very limited python shell for experimenting with your program. What you are looking for is an IDE with a python shell and debugging capabilities. See this page to find one : http://wiki.python.org/moin/IntegratedDevelopmentEnvironments

cheers,

Philippe

Reply all
Reply to author
Forward
0 new messages