我有一些类可以访问mongoDB中的集合。我为每个类创建了很多方法。现在我想知道是否有办法实现这些方法一次,然后我的mongoDB类只包含字段?看看这个例子:
#mongoBase.py
class MongoBase():
def insert()
pass
def update()
pass
#user.py
class User(MongoBase):
# Here should be only fields declaration and when I call .insert(), the fields should be inserted.
我使用Java反射在Java中实现了它。但我在python里找不到这样的东西。你知道吗
我很确定只要在父类中引用
self
,就可以实现您想要做的事情。你知道吗以下是我使用的代码:
下面是它的工作原理:
相关问题 更多 >
编程相关推荐