Trying to use "Programming Python" (Lutz), getting module errors.

Steve Holden sholden at holdenweb.com
Tue May 7 08:34:53 EDT 2002


"John Machin" <sjmachin at lexicon.net> wrote in message
news:c76ff6fc.0205061540.6e68480f at posting.google.com...
> "Steve Holden" <sholden at holdenweb.com> wrote in message
news:<yNuB8.58294$v92.20236 at atlpnn01.usenetserver.com>...
> > "Tiberius Teng" <tiberius at ms28.hinet.net> wrote in message
> > news:6c92a8bc.0205060225.46b1c6c9 at posting.google.com...
> > > robline at purdue.edu (Rob Lineberger) wrote in message
> >  news:<84773476.0205052134.8c1d533 at posting.google.com>...
>
> [Rob Lineberger]
> Tried setting PYTHONPATH to C:\Python22\Lib but that didn't work
> either.
>
> -> PYTHONPATH should include that already.
>
> [Tiberius Teng]
> However if you put your spam.py in C:\Python22\Lib then typing 'import
> spam' inside Pythonwin / IDLE should work ...
>
> -> Ugh. *DON'T* put your own files in there. Do you really want to run
> the risk of overwriting a Python-supplied file with one of your own?
> Also think ahead to when the next version of Python comes out. Do you
> really want to have to move all your files to c:\python23\lib ? How
> will you know which are yours?
>
> [Rob Lineberger]
> I'm trying to learn Python
> [Steve Holden]
> ... writing a site-specific <python>/Lib/sitecustomize.py
>
> -> Correct, but is this useful advice to a newbie at the level of
> "can't work out where to put his module so that he can import it"?
>
Possibly not, but it *was* preceded by advice to set PYTHONPATH and examine
the role of sys.path.

> Here's an alternative:
> 1. Make a directory called (say) c:\mypy.
> 2. Save spam.py in c:\mypy
> 3. Fire up a DOS box / Command Prompt / whatever window.
> 4. DOS_prompt> cd \mypy
> 5. DOS_prompt> python
> 6. >>> import spam
> 7. >>> spam.some_function()

Correct, but is this helpful to a newbie who wants to run his programs
somewhere other than where they live? :-)

Seriously, I hope the combination of suggestions Rob has received (including
yours, which highlights the role of the current directory) will have helped
him solve his problem.

regards
 Steve
--

Steve Holden: http://www.holdenweb.com/ ; Python Web Programming:
http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list