recedence - file vs package

아래와 같은 상황에서 우선순위는?

1. file named bar
/foo/bar.py

2. package named bar
/foo/bar/__init__.py

3. directory named bar
/foo/bar

// which of the 3 will below line import?
from foo import bar

정답은 2. package, 1. file, 3. directory 순서다.

init파일이 없는 directory도 package와 크게 다를 바 없지만 이 경우 우선순위에서 차이가 난다.

더 자세하게 알고싶다면 PEP 420을 읽어보자.

출처: https://stackoverflow.com/a/64738456

좋은 웹페이지 즐겨찾기