简体   繁体   中英

Should I create new python packages by default as namespace packages?

Python 3.3 has implicit namespace packages (PEP420) and in Python 2.7 packages can be marked as namespace packages through adding two lines into __init__py. See How do I create a namespace package in python .

Given the features the packages enable, it looks like that new packages should be created as namespace packages by default.

Normal python packages should only be used in exceptional cases where the need for a "closed" package is obvious.

What would be drawback of this approach ?

PEP 420 notes regular packages have a performance advantage:

There is no intention to remove support of regular packages. If a developer knows that her package will never be a portion of a namespace package, then there is a performance advantage to it being a regular package (with an __init__.py ). Creation and loading of a regular package can take place immediately when it is located along the path. With namespace packages, all entries in the path must be scanned before the package is created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM