w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Calling modules from different packages in a python Project

Within the __init__.py file, put:

from myfile import *

for instance:

pythonds/test/parens.py
pythonds/test/__init__.py

Where the __init__.py would contain:

from parens import *

That's the dirty quick-fix version for older python versions. Considering you have multiple subdirectories something along the lines of (see blow) would be better for all python versions:

In your __init__.py in the folder test place:

__all__ = ['tacos','falaffels']
from test.tacos import factory
from test.falaffels import stand

If you have the following folder structure the above should work:

main.py
/test/
    __init__.py
    tacos.py
    falaffels.py

Also just noticed that this might be a duplicate of: How do I write good/correct __init__.py files





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.