How to search using python console

Is there a way to search for a specific package / function using keywords in the Python console?

For example, I can search for "pdf" for tasks related to PDF.

+7
python
source share
9 answers

The pydoc -k flag pydoc -k for documentation.

 pydoc -k <keyword> Search for a keyword in the synopsis lines of all available modules. 

From the terminal, run.

 $ pydoc -k pdf 

.. eg:

 $ pydoc -k pdf PdfImagePlugin wx.lib.pdfwin PIL.PdfImagePlugin 

It does not search for documentation contents, but searches for all module names - if that is not enough, I would suggest using Google or StackOverflow to search for a “Python PDF module” or similar

+8
source share

You can use the help to access docstrings from different imported modules, for example, try the following:

 help(math) 

and you get an error message,

 import math help(math) 

and you will get a list of available methods in the module, but only AFTER you have imported it. It also works with individual functions, for example. after importing the math check:

 help(math.sin) 

To work with pdf, you probably have to install a third-party module. A quick search led me to a result that I have not tried:

http://www.devshed.com/c/a/Python/Python-for-PDF-Generation/

+8
source share

help ("modules")

 >>> 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". >>> 
+5
source share

You can search for modules containing "pdf" in your description by running the help("modules pdf") command help("modules pdf") .

+4
source share

pip is a great resource. If pip is installed (if you don’t have one, the instructions are here ), and then using the Windows shell you can do the following:

 pip search pdf 

It returns many options.

 C:\Python27\Scripts>pip search pdf mwlib.rl - generate pdfs from mediawiki markup slc.publications - A content type to store and parse pdf publications PyPDFLite - Simple PDF Writer. pdfminer - PDF parser and analyzer zopyx.convert - A Python interface to XSL-FO libraries (Conversion HTML to PDF, RTF, DOCX, WML and ODT) WeasyPrint - WeasyPrint converts web documents to PDF. zopyx.convert2 - A Python interface for the conversion of HTML to PDF, RTF, DOCX, WML and ODT) - belongs to zopyx.smartprintng.core collective.pdfpeek - A Plone 4 product that generates image thumbnail previews of PDF files stored on ATFile based objects. pisa - PDF generator using HTML and CSS 

and etc.

+3
source share

(Years later) Now I use peak search
and yolk -M or -H packagename: -M for metadata, -H to go to your web page.


To find PyPI package information (Python Package Index) locally, try pypi-grep . Example: pypi-grep 'pyqt' →

 # day status packagename version homepage summary 2009-06-07 3 "pydee" 0.4.11 http://code.google.com/p/pydee/ Pydee development environment and its PyQt4-based IDE tools: ... 2009-06-05 4 "Sandbox" 0.9.5 http://www.qtrac.eu/sandbox.html A PyQt4-based alternative to IDLE ... 

pypi-grep is just a file with one long line per PyPI package, with the information you see above, plus a trivial bash script to egrep file.
What for? Local file grabbing is very fast and simple, for old Unix guys and simple searches: "what is XYZ?"

hg clone http://bitbucket.org/denisb/pypi-grep/ should download pypi-grep and pypi-grepfile-2009-06-08 or the like; move them to a directory in your PATH. (First easy_install hg if you don't have hg .)

Notes:

pypi-grepfile has only one version for each package, the newest; multi-line summaries add up to one long line (which I cut into pypi pypi-grep | less -iS ).

pypi-grep -h lists a few options

The data is obtained from http://pypi.python.org/pypi xmlrpc, but be careful: some packages in list_packages do not have releases or no packages, and several timeouts are issued (Timeout_xmlrpclib); what you see is all that you get.

Feedback is welcome.

+2
source share

In the help console (object):

 Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> help(dir) Help on built-in function dir in module __builtin__: dir(...) dir([object]) -> list of strings .... 

Unfortunately, there is no help for pdf:

 >>> help(pdf) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'pdf' is not defined >>> 

As paffnucy said, try finding the internet (SO works very well :)

This site may also be useful: http://www.gotapi.com/python

+1
source share

Recursive thinking:

 >>> help(help) Help on _Helper in module site object: class _Helper(builtins.object) | Define the builtin 'help'. | This is a wrapper around **pydoc.help** (with a twist). | ... 

from here:

 >>> import pydoc >>> help(pydoc) Help on module pydoc: .... 

There is a lot of essential information about searching in python docs.

+1
source share

Try help() or dir() . AFAIR there is no native support for PDF-related tasks in a simple Python installation. Another way to find help for Python modules is google;)

Documentation:

http://docs.python.org/library/functions.html#help

http://docs.python.org/library/functions.html#dir

EDIT:

 >>> import os >>> def search_help(keyword): ... os.system('python Lib/pydoc.py -k %s' % keyword) ... >>> search_help('math') cmath - This module is always available. It provides access to mathematical math - This module is always available. It provides access to the test.test_cmath test.test_math >>> search_help('pdf') >>> _ 

You should have the main python python in your path. And it will not work under IDLE. NTN.

0
source share

All Articles