How to search help using python console

前端 未结 10 1300
长发绾君心
长发绾君心 2021-02-08 20:25

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

For example, I may want to search \"pdf\" for pdf related tasks.

相关标签:
10条回答
  • 2021-02-08 20:44

    (Years later) I now use pip search
    and yolk -M or -H packagename: -M for metadata, -H to browse to its web page .


    To search PyPI (Python Package Index) package info locally, try pypi-grep. An 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 info you see above, plus a trivial bash script to egrep the file.
    Why ? Grepping a local file is very fast and very simple, for old Unix guys and simple searches: "what's 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:

    the pypi-grepfile has only one version per package, the newest; multiline summaries are folded to one long line (which I chop with pypi-grep | less -iS).

    pypi-grep -h lists a few options

    The data comes from http://pypi.python.org/pypi xmlrpc, but beware: some packages in list_packages have no package_releases or no releasedata, and a few releasedatas timeout (timeout_xmlrpclib); what you see is All you get.

    Feedback is welcome.

    0 讨论(0)
  • 2021-02-08 20:44

    Try help() or dir(). AFAIR there's no builtin support for pdf-related tasks in plain Python installation. Another way to find help for Python modules is to google ;)

    Docs:

    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 have to have main python dir in your path. And it won't work under IDLE. HTH.

    0 讨论(0)
  • 2021-02-08 20:47

    Thinking recursively:

    >>> 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: ....
    

    lots of essential info on search in python docs there.

    0 讨论(0)
  • 2021-02-08 20:48

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

    0 讨论(0)
  • 2021-02-08 20:54

    In console type help(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
    ....    
    

    Unfortunatelly 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 searching internet (SO works wery well :)

    This site can be helpful as well: http://www.gotapi.com/python

    0 讨论(0)
  • 2021-02-08 20:58

    The pydoc -k flag searches the documentation.

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

    From a terminal, run..

    $ pydoc -k pdf
    

    ..for example:

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

    It doesn't search the contents of the documentation, but it searches all module names - if that's not enough, I'd suggest using Google or StackOverflow to search for "Python PDF module" or similar

    0 讨论(0)
提交回复
热议问题