Print a year's calendar.
(END)
>>>
Listing 13.6 shows a quick description of the prcal function and the arguments it accepts. Notice
also that help calls prcal a “method” of the calendar module. Remember that method is
another term for a function stored within a module.
Watch Out!: Do I Need to Import a Module to Use help on It?
You may have stumbled onto the fact that you do not have to import a module in order
to get help on it or use the dir function on it. For example, without importing the
calendar function, you can issue the command help('calendar'). However,
the information you get this way may be lacking. It is always a best practice to import a
module before performing any function on it, including help or dir.
Using the information provided by help, you can try out the calendar module’s prcal method,
as shown in Listing 13.7.
LISTING 13.7 Using the prcal Function of calendar
Click here to view code image
>>> import calendar
>>> calendar.prcal(2014)
2014
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 1 2 1 2
6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9
13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16
20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23
27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30
31
April May June
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 1 2 3 4 1
...
Look back to Listing 13.6 and compare the help syntax description to the actual use of the syntax in
Listing 13.7. You can see that help just gives you a push in the right direction. Trying it out for
yourself will help you clearly understand how to use a module’s function.
Try It Yourself: Explore the Modules on Your Raspberry Pi
In the following steps, you are going to explore the Python modules currently available
on your Raspberry Pi. You will get to try a new method of looking for the .py module
files, and you are going to get to do a little Easter egg hunting. Follow these steps:
- If you have not already done so, power up your Raspberry Pi and log in to the