如何在Python控制台中搜索帮助
有没有什么办法可以在Python控制台里用关键词搜索特定的包或者函数呢?
比如说,我可能想用“pdf”这个词来搜索跟pdf相关的任务。
10 个回答
7
这个命令是用来获取关于“模块”的帮助信息的。模块在编程中可以理解为一些预先写好的代码,能够帮助你完成特定的任务。通过这个命令,你可以查看有哪些模块可用,以及它们的功能和用法。
>>> help( "modules" )
Please wait a moment while I gather a list of all available modules...
C:\Program Files\Python26\lib\pkgutil.py:110: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to the wx package as soon
__import__(name)
ArgImagePlugin WmfImagePlugin dbhash pyclbr
BaseHTTPServer XVThumbImagePlugin decimal pydoc
Bastion XbmImagePlugin difflib pydoc_topics
BdfFontFile XpmImagePlugin dircache pyexpat
BmpImagePlugin _LWPCookieJar dis quopri
BufrStubImagePlugin _MozillaCookieJar distutils random
CGIHTTPServer __builtin__ doctest re
Canvas __future__ dumbdbm repr
ConfigParser _abcoll dummy_thread rexec
ContainerIO _ast dummy_threading rfc822
Cookie _bisect email rlcompleter
CurImagePlugin _bsddb encodings robotparser
DcxImagePlugin _bytesio errno runpy
Dialog _codecs exceptions sched
DocXMLRPCServer _codecs_cn filecmp select
EpsImagePlugin _codecs_hk fileinput sets
ExifTags _codecs_iso2022 fnmatch sgmllib
FileDialog _codecs_jp formatter sha
FitsStubImagePlugin _codecs_kr fpformat shelve
FixTk _codecs_tw fractions shlex
FliImagePlugin _collections ftplib shutil
FontFile _csv functools signal
FpxImagePlugin _ctypes future_builtins site
GbrImagePlugin _ctypes_test gc smtpd
GdImageFile _elementtree genericpath smtplib
GifImagePlugin _fileio getopt sndhdr
GimpGradientFile _functools getpass socket
GimpPaletteFile _hashlib gettext sqlite3
GribStubImagePlugin _heapq glob sre
HTMLParser _hotshot gzip sre_compile
Hdf5StubImagePlugin _imaging hashlib sre_constants
IcnsImagePlugin _imagingft heapq sre_parse
IcoImagePlugin _imagingmath hmac ssl
ImImagePlugin _imagingtk hotshot stat
Image _json htmlentitydefs statvfs
ImageChops _locale htmllib string
ImageColor _lsprof httplib stringold
ImageDraw _md5 idlelib stringprep
ImageDraw2 _msi ihooks strop
ImageEnhance _multibytecodec imageop struct
ImageFile _multiprocessing imaplib subprocess
ImageFileIO _random imghdr sunau
ImageFilter _sha imp sunaudio
ImageFont _sha256 imputil symbol
ImageGL _sha512 inspect symtable
ImageGrab _socket io sys
ImageMath _sqlite3 itertools tabnanny
ImageMode _sre json tarfile
ImageOps _ssl keyword telnetlib
ImagePalette _strptime lib2to3 tempfile
ImagePath _struct linecache test
ImageQt _subprocess locale textwrap
ImageSequence _symtable logging this
ImageStat _testcapi macpath thread
ImageTk _threading_local macurl2path threading
ImageTransform _tkinter mailbox time
ImageWin _warnings mailcap timeit
ImtImagePlugin _weakref markupbase tkColorChooser
IptcImagePlugin _winreg marshal tkCommonDialog
JpegImagePlugin abc math tkFileDialog
McIdasImagePlugin aifc md5 tkFont
MicImagePlugin anydbm mhlib tkMessageBox
MimeWriter array mimetools tkSimpleDialog
MpegImagePlugin ast mimetypes toaiff
MspImagePlugin asynchat mimify token
OleFileIO asyncore mmap tokenize
PIL atexit modulefinder trace
PSDraw audiodev msilib traceback
PaletteFile audioop msvcrt tty
PalmImagePlugin base64 multifile turtle
PcdImagePlugin bdb multiprocessing types
PcfFontFile binascii mutex unicodedata
PcxImagePlugin binhex netrc unittest
PdfImagePlugin bisect new update_manifest
PixarImagePlugin bsddb nntplib urllib
PngImagePlugin bz2 nt urllib2
PpmImagePlugin cPickle ntpath urlparse
PsdImagePlugin cProfile nturl2path user
Queue cStringIO numbers uu
ScrolledText calendar opcode uuid
SgiImagePlugin cgi operator warnings
SimpleDialog cgitb optparse wave
SimpleHTTPServer chunk os weakref
SimpleXMLRPCServer cmath os2emxpath webbrowser
SocketServer cmd parser whichdb
SpiderImagePlugin code pdb winsound
StringIO codecs pickle wsgiref
SunImagePlugin codeop pickletools wx
TarIO collections pipes wxPython
TgaImagePlugin colorsys pkgutil wxversion
TiffImagePlugin commands platform xdrlib
TiffTags compileall plistlib xml
Tix compiler popen2 xmllib
Tkconstants contextlib poplib xmlrpclib
Tkdnd cookielib posixfile xxsubtype
Tkinter copy posixpath zipfile
UserDict copy_reg pprint zipimport
UserList csv profile zlib
UserString ctypes pstats
WalImageFile curses pty
WbmpImagePlugin datetime py_compile
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
>>>
9
你可以使用帮助命令来查看你导入的不同模块的文档说明,比如可以试试下面这个:
help(math)
这样会出现一个错误,
import math
help(math)
然后你会看到这个模块里可用的方法列表,但前提是你得先导入它。这个方法也适用于单独的函数,比如在导入了数学模块后,你可以试试:
help(math.sin)
如果你想处理PDF文件,可能需要安装一个第三方模块。我快速搜索了一下,找到了这个结果,不过我还没试过:
http://www.devshed.com/c/a/Python/Python-for-PDF-Generation/
12
pydoc -k
这个命令可以用来搜索文档。
pydoc -k <keyword>
Search for a keyword in the synopsis lines of all available modules.
在终端里运行这个命令..
$ pydoc -k pdf
..比如说:
$ pydoc -k pdf
PdfImagePlugin
wx.lib.pdfwin
PIL.PdfImagePlugin
它并不是在文档的内容里搜索,而是查找所有模块的名字。如果这样还不够的话,我建议你可以用谷歌或者StackOverflow搜索“Python PDF模块”或者类似的关键词。