Thx Rob. yes i know it's related to search path, but i don't know how to set it in a practical way (beside hard coding). my concern is, if i want to create a custom module/library, i don't know what py file will import it and where the working directory should be. sometime like my example, even i don't know where the root directory of my module will place, and i expect it can place in anywhere, how should i set the sys.path? i know that maybe a stupid question, please forgive me, i'm just a newbie. i have read all online documents in python.org. but i wouldn't find the answer.
yes, i'm asking is it normally only put one class in one py file. thanks for your advice. But if i put a set of classes in a py file as a module, will it increase the dependency of each class? back to my example, of course, i can put BaseA and ClassA together in one py file. what should i do when i need to add one more class later, "ClassB", which also extend BaseA. Put it into the same file or in a new file? if put in in the same file, i think it should difficult to maintain versioning. i'm quite confuse in this, maybe because i learn Java before. Thx again, Rob. "Rob Emmons" <[EMAIL PROTECTED]> ??? news:[EMAIL PROTECTED] ???... > > hi all, > > i have question on how to design a module structure. > > for example, i have 3 files. > > [somewhere]/main.py > > [somewhere]/myLib/Base/BaseA.py > > [somewhere]/myLib/ClassA.py > > .... > > ..... > > It's fine when i run main.py. > > however when i run ClassA.py 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. > > Rob > > -- http://mail.python.org/mailman/listinfo/python-list