How to organize source code and "import"s???

Tian wangtianthu at
Mon Mar 28 06:04:18 CEST 2005

I am writing a python program which needs to support some plug-ins. I
have an XML file storing some dynamic structures. XML file records some
class names whose instance needs to be created in the run time while
parsing the XML file. I wonder what is the best solution for this

I also have some problem about the "import". How should I design my
Say, I have all code locates at c:\projects\sami, "c:\project" is in my
PYTHONPATH environment variable. Suppose my folder structure is like

projects\             <-----this directory is in PYTHONPATH
                    <---no instance for this one

Each file in \projects\sami\plugins contains a class with a same name
as the file, ( has class ExtClassA), the instance of these
classes need to be created at runtime while functions in
is parsing an XML file. is the start point of the program.

Other files in the \projects\sami\ and projects\sami\support are
supporting modules.

1. What should I write in each ???
   In "", if I need functions in "", should I write
"import proc"?  If I need functions in "", can i write "import
support.helper"?? what else should I do to support all these?

2. What is the best way to make instance of a class from a string type
name? One method I have successfully tried is using "from SomeWhere
import *", then get class from globals() and make instance. But How can
I import all "ExtClass?.py"? Where should I write these import codes?

More information about the Python-list mailing list