好的,我知道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()函数,但它不适用于我或者当我添加' '它没有给我任何信息
>>> 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'
答案 0 :(得分: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
会为您传递的特定函数打印帮助。
答案 1 :(得分:1)
除了help()
提供的内置文档外,请不要忘记excellent online documentation。您可以查看module index(Python 2链接),或只是像python sys.path
这样的google,通常第一个链接会将您带到正确的位置。一旦你在那里,你可以通过左上角的下拉菜单选择你正在使用的确切版本。