看起来很冗余的模块和类名

法案

在创建带有类的包时,需要一些有关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但这似乎不是一个好主意,因为我可能会在辅助程序包中添加很多内容...

阮狗

您可以将其导入到 __init__

# db/__init__.py
from .mssql import Mssql

现在,您可以做得更短

from db import Mssql

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章