2010-09-24 2 views

Répondre

2

Oui, vous le pouvez, il est d'une manière assez sale pour le faire, mais il est bon pour le débogage, etc

from pprint import pprint 

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

ce n'est pas même proche de toutes les variables liées – aaronasterling

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() et locals() renvoient chacune un dictionnaire représentant la table des symboles dans des portées mondiales et locales respectivement.

Questions connexes