Python SQLAlchemy&;动态设置表列值

Python SQLAlchemy&;动态设置表列值,python,sqlalchemy,Python,Sqlalchemy,尝试这样做: meta = MetaData(bind=engine) meta.reflect(bind=engine, schema='schema') Mapper(Table, meta.tables['schema.table']) t = Table("schema.table", meta, autoload=True, autoload_with=engine) map = {'Col1': 'full_local_col1_name', 'Col2': 'full_local

尝试这样做:

meta = MetaData(bind=engine)
meta.reflect(bind=engine, schema='schema')
Mapper(Table, meta.tables['schema.table'])

t = Table("schema.table", meta, autoload=True, autoload_with=engine)
map = {'Col1': 'full_local_col1_name', 'Col2': 'full_local_col2_name'}

for remote, local in map.items():
    t.set(local, values[remote])
其思想是,
values
是从另一个服务获取的
Dictionary
对象,我正在将列名映射到本地表


我怎样才能做到这一点?SQLAlchemy的
类没有
集合
方法。

不确定要做什么。。您是在尝试插入、更新、更改还是完全不同的内容?您可以为insert执行此操作

meta = MetaData(bind=engine)
meta.reflect(bind=engine, schema='schema')
Mapper(Table, meta.tables['schema.table'])

t = Table("schema.table", meta, autoload=True, autoload_with=engine)
map = {'Col1': 'full_local_col1_name', 'Col2': 'full_local_col2_name'}

t.insert().values(**{local: values[remote] for remote, local in map.items()})