3

在 Python 解释器中:

有哪些方法可以了解我拥有的包裹?

>>> man sys
File "<stdin>", line 1
    man sys
      ^

SyntaxError:无效的语法

>>> sys --help
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bad operand type for unary -: '_Helper'

更正:

>>> help(sys)
...

现在,我如何查看我的 sys.path 上所有可用的包?并查看它们的后续用法和文档。我知道我可以轻松下载 PDF,但所有这些东西都已经准备好了,我不想复制文件。

谢谢!

4

3 回答 3

7

你可以看一下help("modules"),它显示了可用模块的列表。要探索特定的模块/类/函数,请使用dir__doc__

>>> import sys
>>> sys.__doc__
"This module ..."

>>> dir(sys)
[..., 'setprofile', ...]

>>> print(sys.setprofile.__doc__)
setprofile(function)

Set the profiling function.  It will be called on each function call
and return.  See the profiler chapter in the library manual.
于 2013-04-12T07:44:43.390 回答
4

Python 有一个广泛的内置帮助系统,您可以通过以下方式访问help()

>>> help()

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> modules

Please wait a moment while I gather a list of all available modules...

BaseHTTPServer      base64              importlib           sha
Bastion             bdb                 imputil             shelve
CGIHTTPServer       binascii            inspect             shlex
Canvas              binhex              io                  shutil
[...]

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".

help> base64
Help on module base64:

NAME
    base64 - RFC 3548: Base16, Base32, Base64 Data Encodings

FILE
    /usr/local/lib/python2.7/base64.py

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

FUNCTIONS
    b16decode(s, casefold=False)
        Decode a Base16 encoded string.

        s is the string to decode.  Optional casefold is a flag specifying whether
        a lowercase alphabet is acceptable as input.  For security purposes, the
        default is False.

        The decoded string is returned.  A TypeError is raised if s were
        incorrectly padded or if there are non-alphabet characters present in the
        string.

    b16encode(s)
        Encode a string using Base16.

        s is the string to encode.  The encoded string is returned.

    b32decode(s, casefold=False, map01=None)
        Decode a Base32 encoded string.

        s is the string to decode.  Optional casefold is a flag specifying whether
        a lowercase alphabet is acceptable as input.  For security purposes, the
        default is False.

        RFC 3548 allows for optional mapping of the digit 0 (zero) to the letter O
        (oh), and for optional mapping of the digit 1 (one) to either the letter I
        (eye) or letter L (el).  The optional argument map01 when not None,
        specifies which letter the digit 1 should be mapped to (when map01 is not
        None, the digit 0 is always mapped to the letter O).  For security
        purposes the default is None, so that 0 and 1 are not allowed in the
        input.

        The decoded string is returned.  A TypeError is raised if s were
        incorrectly padded or if there are non-alphabet characters present in the
        string.

    b32encode(s)
        Encode a string using Base32.

        s is the string to encode.  The encoded string is returned.
于 2013-04-12T07:46:02.660 回答
1

有一个名为 nullege 的搜索引擎,用于查找特定模块或对象在源代码中的使用方式。

请参阅操作系统的示例

我在github 上为此编写了一个 python 接口

于 2013-04-12T08:27:19.610 回答