[英]Python package naming issue
I have a python package named gutils, which contains a lot of useful tools for development, some of them are generic, some of them use reportlabs and the most important part forms a layer of abstraction on top of django, customizing a lot of default behaviour 我有一个名为gutils的python程序包,其中包含许多有用的开发工具,其中一些是通用的,其中一些使用reportlabs,最重要的部分在django之上形成了抽象层,自定义了许多默认行为
I would like to keep the convention of the exterior interface similar to django's, as to not add complexity to the development proccess.. 我想使外部接口的约定与django相似,以免增加开发过程的复杂性。
I have this structure (as an example): 我有这个结构(例如):
gutils
|---- django
|
|----forms
|
|---widgets.py
The problem is, inside this widgets.py file, the imports resolve to the current subpackage. 问题是,在此widgets.py文件中,导入解析为当前子包。 For example:
例如:
from django.forms import TextInput
Is treated as if it were: 被视为:
from gutils.django.forms import TextInput
As a workaround, I've named the top-level package gdjango, but it looks awkward. 作为一种解决方法,我将顶级程序包命名为gdjango,但它看起来很尴尬。
So, the question is: 因此,问题是:
Is there a way to reference the real django package from within the gutils.django package? 是否可以从gutils.django包中引用实际的django包?
NOTE: I'm using python 3 注意:我正在使用python 3
If you're dealing with a package, for example, like this: 例如,如果要处理软件包,则如下所示:
mypackage /
mypackagesubdir /
myfile.py
mypackagesubdirII /
myfileII.py
and you're editting myfile.py
, import myfileII
like import .mypackagessubdirII.myfileII
. 并且您正在编辑
myfile.py
, myfileII
像import .mypackagessubdirII.myfileII
一样import .mypackagessubdirII.myfileII
。 .
means the root of the package. 表示包的根。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.