Hello World!

Python Help and Your Modules

Posted: April 6, 2009 at 12:00 am

Warren: In the book, we talked a bit about Python’s help system. This is something that can give you help on using Python’s built-in modules and functions as well as external modules and functions. But we didn’t tell you how to add help to your own modules. In this post, we will. I’m going to let Carter take it from here.
Carter: Hi! It’s Carter here. This blog post is a guide to adding help to your Python modules. We will be starting with our TempConv module from Chapter 15:
# this is the file “my_module.py”# we’re going to use it in another programdef c_to_f(celsius):fahrenheit = celsius * 9.0 / 5 + 32return fahrenheit
First, let’s see what help() brings up in Python:
>>> import my_moduleTraceback (most recent call last):File “”, line 1, in ImportError: No module named my_module

Oops! We forgot that Python can’t find our module unless it’s in a folder where python can find it. Navigate to this folder in Windows Explorer (or your favourite file browser):
C:\Python25\Lib\site-packages\Among other things, you should see a Pygame folder, a PythonCard folder, and easygui.py (you might have to scroll down). Save my_module.py there, restart IDLE (or SPE, or Python Shell), and then try importing it again …