Section 12.8 Debugging
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().
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']
Checkpoint 12.8.1.
11-9-1: Which of these options will find the methods of the time library?
dir(time)
Correct! The dir() command helps to find the methods of a given module.
import time
This will import the time module.
help(time)
This will not work.
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.
Checkpoint 12.8.2.
Fix the regex equation so that the code matches any dollar sign ($) followed by an integer or float.