Kristian Rink wrote:
Hi all;

currently I am trying to get some structure into my Python / SOAP project now 
that the threading issue is gone (thanks lots, Kent!); so I created a package 
structure and __init__.py files according to [1], so my project tree looks 
somewhat like this:

$PROJECTROOT
/start.py
/Server
/Server/Core/
/Server/Core/__init__.py
/Server/Core/DMServer.py
..
/Server/Generic/
/Server/Generic/__init__.py
/Server/Generic/DBLink.py
..


Do you have a /Server/__init__.py? I think you must or you wouldn't be able to import DMServer but you don't show it above...


$PROJECTROOT is exported to PYTHONPATH and also shows up in sys.path. Now, the 
following is about
to happen:

start.py (which is the launcher for the server) basically does an

.. from Server.Core import DMServer ..

which works. Anyhow, DMServer.py contains

. from Server.Generic import DBLink .


which doesn't work. This is sort of confusing me since, according to what I read in the Python it
should be possible to access modules from inside a package using this way. Am I mistaking in any
essential point?

No, everything above looks fine. Please post the exact error message you are getting (copy / paste the whole thing including the stack trace).


One problem I have seen in Jython (not sure if CPython does the same thing) is that errors in an imported module can show up as a failure to import the importing module. In other words if something that DBLink imports fails to load, it could cause an import error on DBLink. The way to track this down is to try to import the modules from the interpreter prompt. For example try
>>> from Server.Generic import DBLink
if this gives you an import error on some other module then try to import that module directly, and so on until you find the actual root error.


Do I have to explicitely tell Python in which paths to look for modules within
every single module?

No

Is there a better way to permanently include a path into Python's "import"
search than to export PYTHONPATH each time before starting the application?

There are alternatives, not necessarily better. These both make your project available to any Python application:
- Put all your project files into Lib/site-packages
- Put a .pth file containing the path to your project into site-packages
http://docs.python.org/lib/module-site.html


Kent

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to