我是一個新的Python用戶:) 是否可以使用命令行獲得給定函數的詳細幫助?是否可以使用命令行獲得給定函數的詳細幫助?
回答
由於蟒蛇告訴你,當你啓動CLI:
Type "help", "copyright", "credits" or "license" for more information. >>>
只要求help:
help(help)
help(list)
help(locals)
import math
help(math)
help(math.atan2)
謝謝!有用 ! – 2012-01-04 20:27:32
@NaimeYidwen:請注意,SO使用Q&A而不是論壇格式。評論意圖不適合(也不適合)討論。爲了感謝某人,你可以對他們的答案進行投票。如果您的問題得到解決,您可以[接受](http://meta.stackexchange.com/questions/5234/)一個答案,它可以讓每個人都知道不需要更多的答案,向其他人推薦答案相同問題和獎勵與聲譽的回答者。 – outis 2012-01-04 22:11:22
...當你得到一個可以解決你的問題的答案時,最好等待幾天後再接受,以防萬一有更好的答案出現。不要擔心接受未解決問題的答案。 – outis 2012-01-04 22:11:31
如果你的意思是使用shell命令行,這裏是一個可能的解決方案:
python -c "help(help)"
對於大多數模塊:
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 '\\')
.....
>>>
如果你的意思,然後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.
比你!有用 !我是關於Python命令提示符:) – 2012-01-04 20:05:38
您可以使用pydoc
考慮安裝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
- 1. 重新定義help_console函數以獲得給定包中函數的幫助
- 2. ConEmu是否可以在一行中獲得命令提示符?
- 3. 是否可以給管道char'|'作爲命令行參數?
- 4. 是否可以使用sl4a運行一些自定義命令?
- 5. BigQuery的命令行工具:得到錯誤的詳細信息
- 6. 是否可以更好地格式化函數的幫助?
- 7. mysql命令行幫助(Windows)
- 8. Ant命令行幫助:iisvdir
- 9. 如何獲得詳細信息!dumpheap windbg命令
- 10. 是否可以從Magento內部訪問codeigniter函數/幫助器?
- 11. 是否可以從applet執行命令?
- 12. 如何從命令行以詳細模式運行STS
- 13. git命令獲取特定文件的提交詳細信息
- 14. 是否可以獲得對「setter」的setter函數的引用?
- 15. 是否可以使用Cortana進行應用內語音命令?
- 16. AWK命令幫助
- 17. 是否可以獲取用戶回覆的電子郵件的詳細信息?
- 18. 是否可以從命令行使用dotTrace分析器?
- 19. 是否可以在Linux中使用命令行構建Eclipse Workspace?
- 20. Java中,新手需要幫助使用命令行參數
- 21. 無法獲得SQL * Plus中SQL命令的幫助
- 22. 是否可以從CentOS命令行執行數據庫插入?
- 23. 是否可以將「未命名」變量傳遞給函數?
- 24. MSBuild複製命令的詳細描述
- 25. 是否可以在vimscript中訪問vim的命令行參數?
- 26. rle命令的幫助
- 27. 幫助gdb的stepi命令
- 28. 使Python錯誤消息更詳細/詳細/具體 - 是否有可能?
- 29. 如何獲得客戶詳細信息+他是否有訂單
- 30. 有沒有好的Java庫可以幫助構建命令行應用程序?
什麼命令行? Python的'>>>'提示符?或者其他一些隨機命令行?如果是的話,哪個命令行? – 2012-01-04 19:04:37