__init__.py and package help

T

TechieInsights

Ok I have read all of the tutorials and documents I could find. I am
running Python 2.6 on windows. The problem I am having with packages
is that they don't show up!

Simple example of what isn't working...
Structure-

pytest/ Root directory of package
__init__.py- code: __all__ = ['folder']
folder/ Another folder in the package
__init__.py- code: __all__ = ['hello']
hello.py- code: print('Hello World')

Then I append the path to sys.path, and try and import...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pytest.folder

What am I doing wrong! It's driving me crazy.
Thanks in advance,
Greg
 
T

TechieInsights

Ok... I figured it out... you can only import packages via the __all__
= ['subpackage/folder']... if you include a module such as hello.py,
it will fail.

Go figures I'd find this right after posting here...

Greg
Ok I have read all of the tutorials and documents I could find. I am
running Python 2.6 on windows. The problem I am having with packages
is that they don't show up!

Simple example of what isn't working...
Structure-

pytest/ Root directory of package
__init__.py- code: __all__ = ['folder']
folder/ Another folder in the package
__init__.py- code: __all__ = ['hello']
hello.py- code: print('Hello World')

Then I append the path to sys.path, and try and import...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pytest.folder

What am I doing wrong! It's driving me crazy.
Thanks in advance,
Greg
 
T

TechieInsights

Thanks

J. Cliff Dyer said:
Ok I have read all of the tutorials and documents I could find. I am
running Python 2.6 on windows. The problem I am having with packages
is that they don't show up!

Simple example of what isn't working...
Structure-

pytest/ Root directory of package
__init__.py- code: __all__ = ['folder']
folder/ Another folder in the package
__init__.py- code: __all__ = ['hello']
hello.py- code: print('Hello World')

Then I append the path to sys.path, and try and import...
sys.path.append(r'E:\dev\test\pytest')
from pytest.folder import hello
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pytest.folder

What am I doing wrong! It's driving me crazy.
Thanks in advance,
Greg

You want

unless your code is in E:\dev\test\pytest\pytest\folder\hello.py

 

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

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top