我使用驱动程序的对象Mapper在运行时定义Cassandra表列(需求与这些类似)。在运行时解析表、列名和列类型。
我试图在运行时使用“type”来定义类,以定义cassandra cqlengine模型。
看起来像python驱动程序中定义的Model类向模型添加了一个元类
@six.add_metaclass(ModelMetaClass)
类模型(BaseModel):
..。
是否有一种使用类型来定义模型的方法?在定义模型类时,我看到了以下错误
from cassandra.cqlengine.models import Model
from cassandra.cqlengine import columns as Columns
attributes_dict = {
'test_id': Columns.Text(primary_key=True)
'test_col1': Columns.Text()
}
RunTimeModel = type ('NewModelName', tuple(Model), attributes_dict)
Error:
RunTimeModel = type ('NewModelName', tuple(Model), attributes_dict)
TypeError: 'ModelMetaClass' object is not iterable发布于 2018-10-22 20:39:45
我将远离其余的部分,但是要回答有关错误的问题,我认为您有一个简单的语法错误,试图从一个非序列参数构造一个元组。相反,可以使用元组文字表示法:
RunTimeModel = type ('NewModelName', (Model,), attributes_dict)https://stackoverflow.com/questions/52789628
复制相似问题