You are probably looking for dir :
With no arguments, return the list of names to the current local scope. With an argument, try to return a list of valid attributes for this object.
This may not be obvious at first, but when you are in a global scope (as is usually the case with the command line interpreter), the "current local scope" is a global scope (in this case __main__ ). That way, it will return all the variables and functions that you defined, all the imported modules, and a few things that are bound to each module or only to __main__ . For example:
$ python3.3 >>> dir() ['__builtins__', '__doc__', '__loader__', '__name__', '__package__'] >>> import sys >>> i = 2+3 >>> dir() ['__builtins__', '__doc__', '__loader__', '__name__', '__package__', 'i', 'sys']
This is always the same as sorted(locals().keys()) , but dir() much easier to type. And of course, it is perfectly parallel with dir(sys) to get the values โโdefined by the sys module, dir(i) , to get the attributes of this integer 5 object, etc.
abarnert
source share