Reputation: 8411
on a django shell i tried
from django import forms
class A(forms.Form):
x = forms.CharField()
ao = A()
import pdb
pdb.run('ao.as_table')
but on the last statement , after hitting continue for the first time i am getting a stacktrace as
/usr/lib/python2.6/pdb.pyc in run(statement, globals, locals)
1218
1219 def run(statement, globals=None, locals=None):
-> 1220 Pdb().run(statement, globals, locals)
1221
1222 def runeval(expression, globals=None, locals=None):
/usr/lib/python2.6/bdb.pyc in run(self, cmd, globals, locals)
370 cmd = cmd+'\n'
371 try:
--> 372 exec cmd in globals, locals
373 except BdbQuit:
374 pass
/usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in <module>()
NameError: name 'ao' is not defined
what went wrong ? :(
Upvotes: 1
Views: 720
Reputation: 36393
Two things.
"ao.as_table()"
with ()
as suffix.locals=locals()
to the function. You can also pass globals=globals()
. Don't use locals() as positional argument, as it will get assigned to globals as run(statement[, globals[, locals]])
takes globals as first argument. So if the first positional argument is locals()
it will be mistaken as globals
while running your code.It should be
pdb.run('print ao.as_table()' locals=locals())
Upvotes: 3
Reputation: 6977
pdb.run('print ao.as_table()', locals())
Basically pass on the locals() dictionary
Upvotes: 4