开发者

Why is __init__.py not being called?

开发者 https://www.devze.com 2023-04-06 20:50 出处:网络
I\'m using Python 2.7 and have the following fil开发者_StackOverflowes: ./__init__.py ./aoeu.py __init__.py has the following contents:

I'm using Python 2.7 and have the following fil开发者_StackOverflowes:

./__init__.py
./aoeu.py

__init__.py has the following contents:

aoeu aoeuaoeu aoeuaoeuaoeu

so I would expect running aoeu.py to error when Python tries to load __init__.py, but it doesn't. The behavior is the same whether PYTHONPATH is set to '.' or unset.

What's going on?


__init__.py makes the enclosing directory a package. It won't be executed unless you actually try to import the package directly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号