[Tutor] Building application namespaces.

Kent Johnson kent37 at tds.net
Fri Apr 22 16:59:41 CEST 2005


David Driver wrote:
> I have generally used python for tasks that are scripty and not
> appish. I have found that I don't know the language very well even
> though I have been scripting with it for about two years. To remedy
> this I am in the process of laying out a mock up for an accounting
> system (GL, AR, AP). This is the first time I have done modules inside
> packages and I am confused about namespaces.
> 
> What I have is a folder structure that looks like this:
> root
> ++ Common
> ++ AP
> ++ AR
> ++ GL
> 
> Each subfolder looks like:
> ++ Common
> ++++ __init__.py
> ++++ sobjs.py (this contains sqlobjects for the domain)
> ++++ validators.py (contains formencode validators for the sqlobjects
> for the domain)
> ++++ exceptions.py
> ++++ folder: view (this will be templates)
> ++++ folder: search (this will contain controllers for lookups)
> ++++ folder: transact (this will contain controllers for creating transactions)
> ++++ folder: maintain (contains folders for maintaining domain objects
> (ie customer maintenance or anything that isn't a busness transaction)
> 
> In the __init__ file I import sobjs, exceptions, validators and I will
> eventually check to see that the user is supposed to be in that
> domain.
> 
> You may laready see what the problem is. When I import Common from the
> script running in the root folder and it runs init all of themodules
> in the  domain (common, GL) package that get imported by __init__have
> no ancesters in their name spaces (is that the correct term?). What I
> wanted was root/common/sobjs.py as common.sobjs not just sobjs.

If I understand the setup correctly it should work. How are you importing Common? If you say
import Common
you should be able to refer to Common.sobjs. If you say
from Common import *
then sobjs will be imported into the main module namespace.

Kent



More information about the Tutor mailing list