在创建带有类的包时,我需要一些关于python命名的建议。
我正在尝试创建一些内部使用的可重用助手包,比如:
from local_helper import email
from local_helper.db import mssql
from local_helper.db import orcale使用文件夹结构:
local_helper\
|-- __init__.py
|-- email.py
+-- db\
|-- __init__.py
|-- mssql.py
|-- orcale.py但是,当我将逻辑实现为一个类时,它变成了:
from local_helper.email import Email
from local_helper.db.mssql import Mssql
from local_helper.db.orcale import Orcale在我看来这是多余的。
我可以把我所有的代码放到__init__.py中,但这看起来不是一个好主意,因为我可能会在助手包中添加很多东西……
发布于 2019-01-28 09:49:06
您可以将其导入到__init__
# db/__init__.py
from .mssql import Mssql现在,你可以用更短的时间
from db import Mssqlhttps://stackoverflow.com/questions/54394520
复制相似问题