[Tutor] python import problem

wesley chun wescpy at gmail.com
Thu Aug 10 00:46:59 CEST 2006


> > if I want to import factory.py into myfile.py, how can I do?
>
> You need to make your folders into packages.
> Its fairly simple, you basically create an init.py file
> But its worth reading about packages in the docs
> Come back here ifv you have any questions after that.
>
> The other way would be to add each folder to
> your PYTHONPATH

the rules for importing modules in packages is going to change over
the next few releases... read up on those changes starting from here:

http://docs.python.org/dev/whatsnew/pep-328.html

the simplest solution, as alan's described, is to put all directories
that have your Python modules in the PYTHONPATH environment variable.
if you are on a Unix-based system, just set this variable in your
shell.  if you are on Win32, right-mouse My Computer -> System
Properties -> Advanced -> Environment Variables -> Edit (User or
System variables) -> Ok.

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list