chrisyeh96 / chrisyeh96.github.io

Personal website
https://chrisyeh96.github.io
MIT License
22 stars 22 forks source link

Solution 1 to Case 2 seems to work for Case 3, too #12

Closed bobbyyan0 closed 4 years ago

bobbyyan0 commented 4 years ago

https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#case-3-syspath-could-change-take-2

Folder structure:

.
├── packA
│   ├── a1.py
│   ├── a2.py
│   └── subA
│       └── sa2.py
└── start.py

start.py:

import packA.a2
print('start.py')

a1.py:

import packA.a2
print('a1.py')

a2.py:

import packA.subA.sa2
print('a2.py')

sa2.py:

print('sa2.py')

Result in the parent directory of packA and start.py:

> python start.py
sa2.py
a2.py
start.py

> python -m packA.a1
sa2.py
a2.py
a1.py

Python 3.7.7

chrisyeh96 commented 4 years ago

Good catch. In retrospect, I'm not sure why I thought this case ("Case 3") was different from the previous case ("Case 2"). I will replace "Case 3" with the current "Case 4".

chrisyeh96 commented 4 years ago

Closed by commit f81e2d2.