[英]Import classes in subpackages into main namespace with Python package
I'm trying to re-organise my code-base into a proper Python package (with subpackages) ready for uploading to PyPI. 我正在尝试将我的代码库重新组织成一个适当的Python包(带有子包),准备好上传到PyPI。 I have the following directories (for testing):
我有以下目录(用于测试):
Py6S/
__init__.py
test.py
Params/
__init__.py
AeroModel.py
AeroModel.py contains: AeroModel.py包含:
class AeroModel:
NO_AEROSOL=0
CONTINENTAL=1
MARITIME=2
URBAN=3
USER=4
DESERT=5
BIOMASS_BURNING=6
STRATOSPHERIC=7
The Py6S init .py contains: Py6S init .py包含:
__all__ = ["Params"]
The Params init .py contains: Params init .py包含:
__all__ = ["AtmosModel", "AeroModel", "AtmosCorr"]
However, when I do from Py6S import *
I get Params available to reference, but not AtmosModel or AeroModel. 但是,当我
from Py6S import *
我可以参考Params,但不能使用AtmosModel或AeroModel。
I want to be able to type from Py6S import *
and get all of AeroModel, AtmosModel, AtmosCorr etc available to use without having to put any module names in front of them. 我希望能够
from Py6S import *
键入并使用所有AeroModel,AtmosModel,AtmosCorr等,而无需在它们前面放置任何模块名称。
if Py6S's __init__.py
has from Params import *
: you'd need to do: 如果Py6S的
__init__.py
from Params import *
:你需要这样做:
import Params
__all__ = ["Params"]
from Params import *
__all__ += Params.__all__
to add those to Py6S's __all__
将它们添加到Py6S的
__all__
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.