我想知道如何判断一个对象是否是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?
type(instance)
- SingleNegationElimination