2014-01-23 67 views
1

好做,我知道DIR()函数,但我得到这一切如何找出哪些模块蟒蛇

>>> dir(sys) 
['__displayhook__', '__doc__', '__excepthook__', '__loader__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_debugmallocstats', '_getframe', '_home', '_mercurial', '_xoptions', 'api_version', 'argv', 'base_exec_prefix', 'base_prefix', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'getwindowsversion', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'last_traceback', 'last_type', 'last_value', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'version', 'version_info', 'warnoptions', 'winver'] 

我不知道任何这些事情。我听到的帮助()函数,但它不为我工作,或者当我加入“”它不给我任何信息

>>> help(path) 
Traceback (most recent call last): 
    File "<pyshell#22>", line 1, in <module> 
    help(path) 
NameError: name 'path' is not defined 

>>> help('path') 
no Python documentation found for 'path' 

回答

3

你叫help正是你打电话dir以同样的方式。因此:

>>> import sys 
>>> help(sys) 

Help on built-in module sys: 

NAME 
    sys 

FILE 
    (built-in) 

MODULE DOCS 
    http://docs.python.org/library/sys 

DESCRIPTION 
    This module provides access to some objects used or maintained by the 
    interpreter and to functions that interact strongly with the interpreter. 
... (lot of text follows) 

由于没有模块也不是符号路径help(path)什么都找不到。并且添加引号将无助于任何事情。但是:

>>> help(sys.path) 

Help on list object: 

class list(object) 
| list() -> new empty list 
... (lot of text follows) 

但请注意,它打印的帮助类上的传递的对象,list的,不能对变量。变量不是python中的第一类对象,所以命令无法发现参数来自sys.path,只能在模块中找到它的帮助。函数有附加到函数对象的帮助,所以help确实为您传递的特定函数打印帮助。

+0

啊完美,第二个代码正是我所需要的。谢谢 – Atlas

1

除了通过help()提供的内置文档,请不要忘记excellent online documentation。您可以查看module index(Python 2链接),也可以查看python sys.path之类的链接,通常第一个链接会帮您找到正确的链接。一旦你在那里,你可以通过左上角的下拉菜单选择你正在使用的确切版本。