In a top
folder I have a python file (helpers.py
) which contains a single function:
def play(name, verbose=False):
if verbose:
print name + "with verbose on"
else:
print name + "verbose off"
And in a subfolder named project
I have second python file (program.py
) that imports and uses helpers.py:
from .. import helpers as hp
def main(device,verbose=False):
hp.play(device)
#here goes the code
if __name__ == "__main__":
#Test the program
main('Foo')
main('Foo', verbose=True)
Both folders contain the __init__.py
file to allow module importing. I want to execute the program.py file to test the main function.
Following How to fix "Attempted relative import in non-package" even with __init__.py I try to run :
python -m top.project.program
getting
# /usr/bin/python: No module named top.project
I don't understand what I am doing wrong. Any help? thanks