Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
DLFCN base64 importlib shutil
IN bdb inspect signal
RPi binascii io site
TYPES binhex itertools sitecustomize
...
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
>>>

Notice the standard library module, RPi, in Listing 13.3. This is a Raspberry Pi–specific Python
module, which contains functions to control the General Purpose Input/Output (GPIO) on the Pi. You
will have to wait until Hour 24, “Working with Advanced Pi/Python Projects,” to learn about that
module!


Did You Know: More Modules, Please
One of the great things about the Python community is its willingness to share. You can
find all kinds of user-created Python modules on the Internet to supplement the standard
library. Besides just using your favorite web search engine, take a look at the Python
Package Index (PyPi), at pypi.python.org/pypi.

Reading a module’s name may give you a clue about what type of functions it contains. However, the
best way to find out what is inside takes a little more work, as you will see in the next section.


Learning About Python Modules


To learn about a module and see a description of its various functions, you use the help function.
For example, suppose you want help on the calendar module. In Listing 13.4, the calendar
module is imported, and the help function is used on it.


LISTING 13.4 Using help to See Module Descriptions


Click here to view code image


>>> import calendar
>>> help(calendar)

Help on module calendar:

NAME
calendar - Calendar printing functions
MODULE REFERENCE
http://docs.python.org/3.2/library/calendar
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
...
CLASSES
builtins.ValueError(builtins.Exception)
IllegalMonthError
Free download pdf