2016-10-25 21 views

回答

0

您可以使用globals()來查看當前文件中所有可訪問的變量/功能:

>>> toto = 1 
>>> tutu = 2 
>>> tata = 3 
>>> globals() 
{ 
    '__builtins__': <module '__builtin__' (built-in)>, 
    'tata': 3, 
    'toto': 1, 
    '__package__': None, 
    '__name__': '__main__', 
    'tutu': 2, 
    '__doc__': None 
} 
+1

謝謝!!!!現在生活更輕鬆! = D – Kys3r

2
>>> toto = 1 
>>> tutu = 2 
>>> tata = 3 
>>> from pprint import pprint 
>>> pprint(globals()) 
{'__builtins__': <module 'builtins' (built-in)>, 
'__doc__': None, 
'__loader__': <class '_frozen_importlib.BuiltinImporter'>, 
'__name__': '__main__', 
'__package__': None, 
'__spec__': None, 
'pprint': <function pprint at 0x7f59687bdc80>, 
'tata': 3, 
'toto': 1, 
'tutu': 2} 
>>> help(globals) 
Help on built-in function globals in module builtins: 

globals() 
    Return the dictionary containing the current scope's global variables. 

    NOTE: Updates to this dictionary *will* affect name lookups in the current 
    global scope and vice-versa. 
(END)