我想知道如何知道给定对象是否是sqlalchemy映射模型的实例。检查对象是否是sqlalchemy模型实例
通常,我会使用isinstance(obj,DeclarativeBase)。但是,在这种情况下,我没有使用DeclarativeBase类(因为它在依赖项目中)。
我想知道这种情况下的最佳做法是什么。
class Person(DeclarativeBase):
__tablename__ = "Persons"
p = Person()
print isinstance(p, DeclarativeBase)
#prints True
#However in my scenario, I do not have the DeclarativeBase available
#since the DeclarativeBase will be constructed in the depending web app
#while my code will act as a library that will be imported into the web app
#what are my alternatives?
提供更多信息! – shahjapan