I did something silly when I started my python project: I named my main file project.py, and I stored a bunch of logic in a package that is also called project. Here's the directory structure:
project.py
project/
other files
Here's the problem: Now I need to import the function main from project.py. But every time I try to import it, python tries to import the package instead of the module.
>>> from project import main
AttributeError: 'module' object has no attribute 'main'
>>> import project
>>> print(project)
>>> <module 'project' from 'c:\temp\project\__init__.pyc'>
Is there any way to fix this without renaming either the folder or the file?
Right now, my solution is to move the logic from project.py to a new file:
contents of project.py:
Then I can import project.main.main() directly.