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 に答える