import and package confusion

Scott David Daniels Scott.Daniels at Acm.Org
Wed Apr 29 14:47:53 EDT 2009


Dale Amon wrote:
> I am going around in circles right now and have to
> admit I do not understand what is going on with
> import of hierarchical packages/modules. Perhaps someone
> can get me on the road again. Here is a subset of what I 
> am trying to accomplish:
> 
> The package directory set up:
> 
> 	VLMLegacy/
>           __init__.py
>           Reader.py
> 	  Conditions.py
>           VLM4997/
>             __init__.py
>             Conditions.py
>           WINGTL/
>             __init__.py
>             Conditions.py
> 
> The inheritance:
> 	object
>           Reader
>             Conditions
>               VLM4997.Conditions
>               WINGTL.Conditions
 >
> Now how do I use import or from to be able to 
> use these modules? The following is not 'real'
> code and is only intended to give some idea of
> what I am trying to accomplish:
> 
> import sys
> sys.path.extend (['../lib', '../bin'])
> 
> import VLMLegacy.VLM4997.Conditions
> import VLMLegacy.WINGTL.Conditions
Each of these imports a module in a subpackage in a package.
> 
> b = VLM4997.Conditions(2)
I see some confusion here.
(1) This should give a NameError('VLM4997')
(2) Even if changed to b = VLMLegacy.VLM4997.Conditions(2),
     You are calling an imported module, rather than a function or class.

So, using my crystal ball (which came back from the shop covered
in some sticky fluid), I guess you might mean:
     import VLMLegacy.VLM4997.Conditions.Conditions as VLM4997_Conditions
     import VLMLegacy.WINGTL.Conditions.Conditions as WINGTL_Conditions
     ...
     b = VLM4997_Conditions(2)
     b.test()
     ...

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list