importing modules symbols from packages.
Richard Béneyt
rbeneyt at free.fr
Sat May 24 09:53:47 EDT 2003
Steven Taschuk a écrit:
> Quoth Richard Béneyt:
> [...]
>
>>"In modspack2.py, I wrote:
>>
>> from pack2.spack1.modspack1 import aSymbol"
>>
>>Sorry.
>>The code was right and the example false, so actually the problem is
>>still there.
>
>
> This is highly strange.
>
> Could you post some very cut-down versions of these files for our
> review and testing? (Make sure, of course, that the cut-down
> versions fail too.)
>
Hi,
I got it !
Actually, I didn't write an accurate example of my code, I thought it
wasn't meaningful but the sub-package, in the example: spack2, had the
same name as the package (in the example pack2) in the real code. So,
actually it was :
python-packages
|
|__ pack1
| |
| |__ __init__.py
| |__ module1.py
| |__ module2.py
| ...
|__ pack2
| |
|__ __init__.py
|__ spack1
| |
| |__ __init__.py
| |__ spack1.py
|
|__ pack2
|
|__ __init__.py
|__ pack2.py
And, In pack2.py, I wrote:
from pack2.spack1.spack1 import aSymbol
I'm not sure of the way python processes this, but I read somewhere on
python.org that packages and sub-packages and modules are stored in the
same namespace, so I tried to change the layout by:
python-packages
|
|__ pack1
| |
| |__ __init__.py
| |__ module1.py
| |__ module2.py
| ...
|__ pack2
| |
|__ __init__.py
|__ spack1
| |
| |__ __init__.py
| |__ spack1.py
|
|__ pack2D
|
|__ __init__.py
|__ pack2D.py
And, In pack2D.py, I wrote:
from pack2.spack1.spack1 import aSymbol
And now it works !
Thanks a lot for having spent time on this.
--
Richard Béneyt
rbeneyt.akis at nerim.fr
More information about the Python-list
mailing list