0

Today I have found something strange on my system, but it could be that I have messed up my python setup (use pyenv on OSX 10.15).

This is my project just for testing

├── lib
│   └── f1.py
└── main.py

main.py

from lib.f1 import hello

def main():
    hello('top level main')
    print('MAIN -- end')

if __name__ == "__main__":
    main()

lib/f1.py

def hello(s: str):
    print(f'Hello {s} from {__file__}')

cli output

$ python -V
Python 2.7.16
$ python main.py 
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from lib.f1 import hello
ImportError: No module named lib.f1

$ python3 -V
Python 3.11.3
$ python3 main.py 
Hello top level main from /<MY_PATH>/lib/f1.py
MAIN -- end

My question is why is this code working on python3 ?

I would expect that it will fail, as on python2.

WebOrCode
  • 6,852
  • 9
  • 43
  • 70

0 Answers0