wtfpython icon indicating copy to clipboard operation
wtfpython copied to clipboard

Relative imports

Open adamerose opened this issue 5 years ago • 1 comments

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

adamerose avatar Oct 29 '20 21:10 adamerose

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

satwikkansal avatar Oct 30 '20 07:10 satwikkansal