Does any language or debug tool have a way to print out the scope chain for examination, so as to look at the different situations of what a scope chain contains?
Asked
Active
Viewed 54 times
1
-
1I'd love to see a tool like this; maybe someone's come up with a DXCore plugin to do this. – Pierreten May 03 '10 at 23:10
1 Answers
2
Firebug does for JavaScript. On the ‘Watch’ tab of the ‘Script’ debugger you can open up the scope chain list a look at each parent scope.
Python can read locals from a parent scope in the language itself if you grab a code object, but the way it handles nested scopes means that only the scoped variables that are actually used are bound:
>>> def a():
... def b():
... print v1
... v1= 1
... v2= 2
... return b
>>> f= a()
>>> f.func_code.co_freevars
('v1',)
>>> f.func_closure
(<cell at 0x7fb601274da8: int object at ...>,)
>>> f.func_closure[0].cell_contents
1
Though both v1
and v2
are defined in the parent scope, only v1
is actually closed over.

bobince
- 528,062
- 107
- 651
- 834