2012-01-04 65 views

回答

4

由於蟒蛇告訴你,當你啓動CLI:

 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 

只要求help

help(help) 
help(list) 
help(locals) 
import math 
help(math) 
help(math.atan2) 
+0

謝謝!有用 ! – 2012-01-04 20:27:32

+0

@NaimeYidwen:請注意,SO使用Q&A而不是論壇格式。評論意圖不適合(也不適合)討論。爲了感謝某人,你可以對他們的答案進行投票。如果您的問題得到解決,您可以[接受](http://meta.stackexchange.com/questions/5234/)一個答案,它可以讓每個人都知道不需要更多的答案,向其他人推薦答案相同問題和獎勵與聲譽的回答者。 – outis 2012-01-04 22:11:22

+0

...當你得到一個可以解決你的問題的答案時,最好等待幾天後再接受,以防萬一有更好的答案出現。不要擔心接受未解決問題的答案。 – outis 2012-01-04 22:11:31

2

如果你的意思是使用shell命令行,這裏是一個可能的解決方案:

python -c "help(help)" 
0

對於大多數模塊:

Python 2.6.7 (r267:88850, Sep 23 2011, 00:28:08) 
.... 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import os 
>>> help(os) 

>>> print os.__doc__ 
OS routines for Mac, NT, or Posix depending on what system we're on. 

This exports: 
    - all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc. 
    - os.path is one of the modules posixpath, or ntpath 
    - os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos' 
    - os.curdir is a string representing the current directory ('.' or ':') 
    - os.pardir is a string representing the parent directory ('..' or '::') 
    - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\') 
    ..... 
>>> 
0

如果你的意思,然後Python的命令提示符:

help(whatever) 

,或者如果whatever是保留字:

help("whatever") 

如果你指的殼或Windows命令提示符,然後使用是pydoc :

C:\Python32>lib\pydoc.py json.dumps 
Help on function dumps in json: 

json.dumps = dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, s 
eparators=None, default=None, **kw) 
    Serialize ``obj`` to a JSON formatted ``str``. 

    If ``skipkeys`` is false then ``dict`` keys that are not basic types 
    (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped 
    instead of raising a ``TypeError``. 

    If ``ensure_ascii`` is false, then the return value can contain non-ASCII 
    characters if they appear in strings contained in ``obj``. Otherwise, all 
    such characters are escaped in JSON strings. 

    If ``check_circular`` is false, then the circular reference check 
    for container types will be skipped and a circular reference will 
    result in an ``OverflowError`` (or worse). 

    If ``allow_nan`` is false, then it will be a ``ValueError`` to 
    serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in 
    strict compliance of the JSON specification, instead of using the 
    JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``). 

    If ``indent`` is a non-negative integer, then JSON array elements and 
    object members will be pretty-printed with that indent level. An indent 
    level of 0 will only insert newlines. ``None`` is the most compact 
    representation. 

    If ``separators`` is an ``(item_separator, dict_separator)`` tuple 
    then it will be used instead of the default ``(', ', ': ')`` separators. 
    ``(',', ':')`` is the most compact JSON representation. 

    ``default(obj)`` is a function that should return a serializable version 
    of obj or raise TypeError. The default simply raises TypeError. 

    To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the 
    ``.default()`` method to serialize additional types), specify it with 
    the ``cls`` kwarg; otherwise ``JSONEncoder`` is used. 
+0

比你!有用 !我是關於Python命令提示符:) – 2012-01-04 20:05:38

3

考慮安裝IPython。它不僅讓您快速方便地訪問help doc strings

In [3]: os.path.expanduser? 
Type:  function 
Base Class: <type 'function'> 
String Form: <function expanduser at 0xb77ffe64> 
Namespace: Interactive 
File:  /usr/lib/python2.7/posixpath.py 
Definition: os.path.expanduser(path) 
Docstring: 
    Expand ~ and ~user constructions. If user or $HOME is unknown, 
    do nothing. 

它也可以幫助你找出什麼屬性/方法的對象必須通過tab completion

os.path.__name__     os.path.ismount 
os.path.__new__      os.path.join 
os.path.__package__     os.path.lexists 
os.path.__reduce__     os.path.normcase 
os.path.__reduce_ex__    os.path.normpath 
os.path.__repr__     os.path.os 
os.path.__setattr__     os.path.pardir 
os.path.__sizeof__     os.path.pathsep 
os.path.__str__      os.path.realpath 
os.path.__subclasshook__   os.path.relpath 
os.path._resolve_link    os.path.samefile 
os.path._varprog     os.path.sameopenfile 
os.path.abspath      os.path.samestat 
os.path.altsep      os.path.sep 
os.path.basename     os.path.split 
os.path.commonprefix    os.path.splitdrive 
os.path.curdir      os.path.splitext 
os.path.defpath      os.path.stat 
os.path.devnull      os.path.supports_unicode_filenames 
os.path.dirname      os.path.sys 
os.path.exists      os.path.walk 
os.path.expanduser     os.path.warnings 

In [4]: os.path.[TAB] 

在Debian/Ubuntu的,IPython中能被安裝與

sudo apt-get install ipython 
相關問題