冗余的模块和类名

2024-04-25 21:40:56 发布

您现在位置:Python中文网/ 问答频道 /正文

在用类创建包时,需要一些关于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中,但这看起来不是个好主意,因为我可能会在helper包中添加很多东西。。。你知道吗


Tags: frompyimporthelper文件夹程序包dbinit