[Q] Inspect variables during execution?
Fredrik Lundh
fredrik at pythonware.com
Thu Mar 1 16:35:07 EST 2001
Daehyok Shin wrote:
> Is there any function helping me to inspect variables for debugging during
> execution?
something like this, perhaps?
#
# code-example-3.py
def keyboard(banner=None):
import code, sys
# use exception trick to pick up the current frame
try:
raise None
except:
frame = sys.exc_info()[2].tb_frame.f_back
# evaluate commands in current namespace
namespace = frame.f_globals.copy()
namespace.update(frame.f_locals)
code.interact(banner=banner, local=namespace)
#
# usage example
def func():
print "START"
a = 10
keyboard()
print "END"
func()
# START
# Python 1.5.2
# Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
# (InteractiveConsole)
# >>> print a
# 10
# >>> print keyboard
# <function keyboard at 9032c8>
# ^Z
# END
Cheers /F
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list