How to write good Python objects?

Andy Todd andy47 at halfcooked.com
Fri Oct 24 05:22:57 EDT 2003


John Ladasky wrote:

> Hi, folks,
> 
[snip]
> 
> One other thing -- I would like to be able to include a statement in
> my program to the effect of: "from my_package import
> my_function_or_class".  Python seems to look for .pyc files in the
> /Lib folder.  By placing a .py file in /Lib, I got it to compile, and
> to be recognized by an import statement.  Is this the right way for
> users to package their own code?  It seems kludgy to me.
> 
> If it matters (it shouldn't), I'm running Python 2.2.2 on Win2000 Pro.
> 
> Thanks for your advice!
> 
> --
> John J. Ladasky Jr., Ph.D.
> Department of Biology
> Johns Hopkins University
> Baltimore MD 21218
> USA
> Earth

You can put your modules anywhere you like. You just need to tell the 
Python interpreter where to look for them. You can do this one of two 
ways, either by setting a PYTHONPATH environment variable;

http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000

Do this on Windows 2000 with Start->Settings->Control Panel->System
Then select the 'Advanced' tab and click on the button labelled 
"Environment variables..."

Or, you can use path configuration (.pth) files;

http://www.python.org/doc/current/lib/module-site.html

On Windows 2000, and with Python installed to C:\Python2.2 you would 
place your file (called, say John.pth) in C:\Python2.2\Lib\site-packages

Regards,
Andy
-- 
--------------------------------------------------------------------------------
 From the desk of Andrew J Todd esq - http://www.halfcooked.com/







More information about the Python-list mailing list