2024-05-29 10:10:49 发布
网友
我在pyexcel的save\ to\ u数据库函数中遇到mapdict参数问题
似乎我仍然需要在文件的开头有一行列名,否则我会出错。mapdict没有指定每列转换为字典后要使用的名称吗
我很不确定这个论点到底是怎么回事
任何帮助都将不胜感激
听着,很简单 如果您有这样的CSV:
brand,sku,description,quantity,price br,qw3234,s sdf sd ,4,23.5 br,qw3234,s sdf sd ,4,23.5 br,qw3234,s sdf sd ,4,23.5 br,qw3234,s sdf sd ,4,23.5
你不需要mapdict
但是如果你的CSV没有第一行 你需要它。例如,我的烧瓶项目中的一个和平:
def article_init_func(row): warehouse = Warehouse.query.filter_by(id=id).first() a = Article() a.pricelist_id = p.id a.sku=row['sku'] a.description=row['description'] a.brand=row['brand'] a.quantity=row['quantity'] a.city=warehouse.city a.price=row['price'] return a map_row = ['brand', 'sku', 'description', 'quantity', 'price'] request.save_to_database( field_name='file', session=db.session, initializer = article_init_func, table=Article, mapdict=map_row)
听着,很简单 如果您有这样的CSV:
你不需要mapdict
但是如果你的CSV没有第一行 你需要它。例如,我的烧瓶项目中的一个和平:
相关问题 更多 >
编程相关推荐