[英]How can I access the list of modules that Python's help('modules') displays?
[英]How can I pass the results of Python's help('modules') output to pbcopy in one line?
就像標題地址一樣,該怎么做? 我愚蠢地嘗試了以下內容,但在這里我將分享愚蠢之處,以便您可以了解我想發生的事情:
myself$ python help('modules') | pbcopy
這是一個好主意嗎:
fout = open('output.txt', 'w')
fout.write(help('modules'))
在我的Ubuntu上,希望也可以在boxen上使用(因為它是標准的python功能),有一個方便的pydoc
命令,因此鍵入非常容易
pydoc modules | pbcopy
我不知道什么是pbcopy,但是我知道這可以解決問題:
python -c 'import urllib; help(urllib)' | pbcopy
至少這絕對是可行的:
python -c 'import urllib; help(urllib)' > file
從man python
:
-c command
Specify the command to execute (see next section). This terminates the option list (following options are passed as arguments to the command).
為了將其復制到剪貼板,您可以將其添加到~/.bashrc
:
pc() { python -c "import $1; help($1);" | xclip -i -selection clipboard; }
然后只需調用pc logging
或pc my_module
或者,您可以將其通過管道傳輸到pbcopy或任何對您有用的文件。
使用pydoc查找文檔並打印。
例:
$ python -c 'import pydoc; print pydoc.getdoc(id)'
id(object) -> integer
Return the identity of an object. This is guaranteed to be unique among
simultaneously existing objects. (Hint: it's the object's memory address.)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.