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

(singke) #1

up into small code chunks is easy to track and manage. Large scripts can be unwieldy and difficult to
debug. Small scripts that import in reusable code “chunks” (that is, modules) are much easier to
handle. Also, when you use modules, you don’t have to reinvent functions for each script.


Exploring Standard Modules


The Python standard library, which contains hundreds of modules, is included when Python is
installed on your system. One of the Python catch phrases is “Python comes with batteries included.”
That catch-phrase applies to the Python standard library, with all its prewritten functions housed in
modules.


Most of the standard library modules can be loosely fit into general categories. (Many of the modules
could fit into multiple categories.) Those categories include the following:


Character strings processing
Data compression and backup
Database management
Date and time tools
File I/O and format processing
Game development tools
Graphics utilities
Internationalization utilities
Internet I/O and format processing
Interprocess communication
Multimedia tools
Network management
Platform-specific commands
Python script development tools
Scientific (including math) utilities
Security management
Web development tools

With so many modules full of functions, it makes sense to search through the standard library for what
you need before you decide to write your own. To determine what modules are loaded in your Python
standard library, use the help function, as shown in Listing 13.3. The listing displays only a small
portion of the entire module list because it is just too long to show the entire list in this book!


LISTING 13.3 Using help to Find Modules


Click here to view code image


>>> help('modules')

Please wait a moment while I gather a list of all available modules...

CDROM audioop imp shlex
Free download pdf