2010-09-24 90 views

回答

2

當然可以,這是一個相當骯髒的方式做到這一點,但它是很好的調試等

from pprint import pprint 

def getCurrentVariableState(): 
    pprint(locals()) 
    pprint(globals()) 
+1

這甚至還沒有接近所有綁定變量 – aaronasterling 2010-09-24 05:39:30

0
dir(...) 
    dir([object]) -> list of strings 

    If called without an argument, return the names in the current scope. 
    Else, return an alphabetized list of names comprising (some of) the attributes 
    of the given object, and of attributes reachable from it. 
    If the object supplies a method named __dir__, it will be used; otherwise 
    the default dir() logic is used and returns: 
     for a module object: the module's attributes. 
     for a class object: its attributes, and recursively the attributes 
     of its bases. 
     for any other object: its attributes, its class's attributes, and 
     recursively the attributes of its class's base classes. 
0

globals()和當地人()返回各自分別代表全局和局部範圍的符號表的字典。