[英]MSSQL to Python
我正在嘗試將數據從MSSQL導入Python-Odoo安裝。 我可以使用以下代碼導入一個字段。 這有效,但我想檢索名稱以外的其他字段。
#Retrieve data through recordset
RecCount =rs.RecordCount
print RecCount
while not rs.EOF:
# print rs.Fields.item('Description').value
# print rs.Fields.item('Price').value
name = rs.Fields.item('Description').value
record = {'name' : name}
filter = [[['name' ,'=', name]]]
product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'search', filter)
if not product_id:
print " Create - " + name
resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', [record])
else:
print "Already in table - " + name
rs.Move(1)
我想導入其他字段,例如條形碼字段。 以下是我嘗試過的操作,但出現錯誤。
#Retrieve data through recordset
RecCount =rs.RecordCount
print RecCount
while not rs.EOF:
# print rs.Fields.item('Description').value
# print rs.Fields.item('Price').value
name = rs.Fields.item('Description').value
barcode = rs.Fields.item('ItemLookupCode').value
record = {'name' : name}
recordbarcode = {'barcode' : barcode}
filter = [[['barcode' ,'=', barcode]]]
product_id = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'search', filter)
if not product_id:
print " Create - " + barcode
resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', ['record']['recordbarcode'] )
else:
print "Already in table - " + barcode
rs.Move(1)
我上面的代碼得到的錯誤是
Traceback (most recent call last):
File "importdataorg.py", line 58, in <module>
resultset = OdooApi.execute_kw(database, uid, pwd, 'product.template', 'create', ['record']['recordbarcode'] )
TypeError: list indices must be integers, not str
我不確定您的錯誤與您使用的任何工具完全相關。
['record']['recordbarcode']
不是有效的Python。
只需在REPL中單獨運行, list indices must be integers, not str
您是否要使用這些變量?
record = {'name' : name}
recordbarcode = {'barcode' : barcode}
如果是這樣,則record['name']
是有效的,但這實際上只是已經可用的name
變量。
也許你想要這本字典
{'name' : name, 'barcode' : barcode}
或兩個字典的列表
[record, recordbarcode]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.