I have a folder with a __init__.py
File __init__.py:
#!/usr/bin/python2
flags="test"
File main.py:
#!/usr/bin/python2
import foldername
def main():
print foldername.flags
if __name__ == '__main__':
main()
Now, when I run ./main.py (from inside the folder), I get the error
ImportError: No module named foldername
Run from the parent folder for
foldername:If you rename
main.pyto__main__.pythen you could run it as (since Python 2.7):python -madds implicitly current directory to your python path (sys.path).If the parent directory for
foldernameis in your python path then you could run the above commands from any directory.