您在這裡

Debugging

24 二月, 2015 - 10:35

Python has some simple and rudimentary built-in documentation that can be quite helpful if you need a quick refresher to trigger your memory about the exact name of a particular method. This documentation can be viewed in the Python interpreter in interactive mode.

You can bring up an interactive help system using help().

>>> help()

Welcome to Python 2.6! This is the online help utility.

If this is your first time using Python, you should definitely check outthe tutorial on the Internet at http://docs.python.org/tutorial/.

Enter the name of any module, keyword, or topic to get help on writingPython programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules","keywords", or "topics". Each module also comes with a one-line summary  of what it does; to list the modules whose summaries contain a given word   such as "spam", type "modules spam". 

help> modules

If you know what module you want to use, you can use the dir() command to find the methods in the module as follows:

>>> import re>>> dir(re)[.. 'compile', 'copy_reg', 'error', 'escape', 'findall','finditer', 'match', 'purge', 'search', 'split', 'sre_compile','sre_parse', 'sub', 'subn', 'sys', 'template']

You can also get a small amount of documentation on a particular method using the dir command.

>>> help (re.search)Help on function search in module re: 

search(pattern, string, flags=0)    Scan through string looking for a match to the pattern, returning 
    a match object, or None if no match was found.
>>>

The built in documentation is not very extensive, but it can be helpful when you are in a hurry or don’t have access to a web browser or search engine.