dir

dir函数用来查看上下文

dir()会列出当前上下文的所有变量、模块、函数等等,把得到的值再传给dir可以像下查看

>>> import fibo, sys
>>> dir(fibo)
['__name__', 'fib', 'fib2']
>>> dir(sys)  
['__displayhook__', '__doc__', '__egginsert', '__excepthook__',
 '__loader__', '__name__', '__package__', '__plen', '__stderr__',
 '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames',
 '_debugmallocstats', '_getframe', '_home', '_mercurial', '_xoptions',
 'abiflags', 'api_version', 'argv', 'base_exec_prefix', 'base_prefix',
 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats',
 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_info',
 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info',
 'float_repr_style', 'getcheckinterval', 'getdefaultencoding',
 'getdlopenflags', 'getfilesystemencoding', 'getobjects', 'getprofile',
 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval',
 'gettotalrefcount', 'gettrace', 'hash_info', 'hexversion',
 'implementation', 'int_info', 'intern', 'maxsize', 'maxunicode',
 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache',
 'platform', 'prefix', 'ps1', 'setcheckinterval', 'setdlopenflags',
 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace',
 'stderr', 'stdin', 'stdout', 'thread_info', 'version', 'version_info',
 'warnoptions']
>>> a = [1, 2, 3, 4, 5]
>>> import fibo
>>> fib = fibo.fib
>>> dir()
['__builtins__', '__name__', 'a', 'fib', 'fibo', 'sys']
原文地址:https://www.cnblogs.com/wangjixianyun/p/2836674.html