Package

  • Thread starter Matthieu Pichaud
  • Start date
M

Matthieu Pichaud

I have a problem organizing my programs in packages and subpackages.

I use python.2.3.3
I built a test structure to try to understand how it worked:

/test
/test/__init__.py (containing: __all__=['test1'])
/test/test1/
/test/test1/__init__.py (containing: __all__=['test2'])
/test/test1/test2/
/test/test1/test2/__init__.py (containing: __all__=['test3'])
/test/test1/test2/test3.py (containing: print 'test3')

Then I run:Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'test2' is not defined


So it seems that I am very limited in the number of subpackages I can
create.
Is it normal? Am I silly organizing my programs like that?

Thanks for your help!

Matth
 
B

bruno at modulix

Matthieu said:
I have a problem organizing my programs in packages and subpackages.

I use python.2.3.3
I built a test structure to try to understand how it worked:

/test
/test/__init__.py (containing: __all__=['test1'])
/test/test1/
/test/test1/__init__.py (containing: __all__=['test2'])
/test/test1/test2/
/test/test1/test2/__init__.py (containing: __all__=['test3'])
/test/test1/test2/test3.py (containing: print 'test3')

Then I run:Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'test2' is not defined

So it seems that I am very limited in the number of subpackages I can
create.

Not at all.
Is it normal?

Yes : when you have nested namespaces, it won't magically become a flat
namespace. There's a mostly clear documention on this in the official
Python tutorial.
Am I silly organizing my programs like that?

Dunno - it depends on the program. But still:
python -c "import this" | grep nested

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top