开发者

Is this method of importing modules, in Python, causing a loop?

开发者 https://www.devze.com 2023-02-03 11:48 出处:网络
app/__ init__.py from blah import test app/x.py from app import * test() Basically, I have an __init__.py file that contains a bu开发者_开发百科nch of imports that will be used throughout the a

app/__ init__.py

from blah import test

app/x.py

from app import *

test()

Basically, I have an __init__.py file that contains a bu开发者_开发百科nch of imports that will be used throughout the app. I've put them all in here to save me having to import them into each file (every file within this folder will use the same imports)

I'm wondering if that from app import * line is causing it to import itself as it is inside the app folder...

Am I doing this correctly?


Subpackages and modules within a package are never imported when the package is imported unless they are explicitly imported within __init__.py. Even if they were, the most that would happen is that the module would contain a reference to itself, which is not considered a problem.

0

精彩评论

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

关注公众号