Newbie: module structure and import question

Rob Emmons rmemmons at
Thu Jan 13 20:59:57 EST 2005

> hi all,
> i have question on how to design a module structure.
> for example, i have 3 files.
> [somewhere]/
> [somewhere]/myLib/Base/
> [somewhere]/myLib/
> ....
> .....
> It's fine when i run
> however when i run individually, it would fail in import
> statment since the import path is incorrect.
> I would like to know is something wrong in my design, or something i
> missed.

I think your issue is your module search path.  Take a look at the doc for
sys.path in the library reference.  These are the directories that python
searchies for modules.  Usually the "." directory is included in this
which makes python search the current working directory.  Your example
fails because your working directories are probably different when you ran
the two modules.  In any case always consider how you've setup sys.path
and your libraries and modules.

> Also, in practical usage, is that one class in one py file?

I'm not exactly clear what your asking -- but I think yor asking if you'd
normally only put one class in one py file.  My answer is no -- generally
you'd put many functions and classes in each py file.  Modules are high
level and should be used to create libraries essentailly -- this means
many fucntions and classes per module.


More information about the Python-list mailing list