wtfpython
wtfpython copied to clipboard
Relative imports
I definitely think this repo should include an example about how messed up relative imports are in Python, just read this thread https://stackoverflow.com/questions/16981921/relative-imports-in-python-3
file structure
main.py
mypackage/
__init__.py
module1.py
module2.py
module1.py
def test():
print("Hello")
module2.py
from .module1 import test
if __name__ == '__main__':
test()
running module2.py
Traceback (most recent call last):
File "C:/_MyFiles/Programming/scratch/subfolder/module2.py", line 1, in <module>
from .module1 import test
ImportError: attempted relative import with no known parent package
Yes, imports are definitely a missing part of this collection. Will add this in the next iteration for sure.
Also related: https://github.com/satwikkansal/wtfpython/issues/133