__init__.py and package help
TechieInsights
GDoermann at gmail.com
Mon Jan 5 14:58:09 EST 2009
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
TechieInsights wrote:
> 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
More information about the Python-list
mailing list