私の現在のスクリプトはExcelファイルに保存しますが、私は自分のmysqlデータベースに直接アップロードしたいと思います。Pythonがmysqlデータベースに保存
for i in range(0, len(names)):
ws.append([names[i], str((float(sells[i])+float(buys[i]))/2.0)])
except:
print('Cannot fetch from this link')
print('Saving the file with name markets.xlsx')
wb.save("markets.xlsx")
は、どのように私は今、次のを持って、ここでのアドバイス、次の次
sql = "INSERT INTO todaysmarkets(Name,value) VALUES(%s,%s)"
****更新*****
を行うためのループを実行します:
cnx = mysql.connector.connect(host='.com', user='', password='', database='')
cursor = cnx.cursor()
for i in range(0, len(names)):
cursor.execute(("INSERT INTO todaysmarkets(Name,value) VALUES(%s,%s)"), (names[i], str((float(sells[i])+float(buys[i]))/2.0)))
cnx.close()
スクリプトはエラーなしで実行されますが、データベースは更新されません。
ですから、のORMを使用していませんどんな種類?あなたはPythonからそれに接続する方法に関するmysqlのドキュメントを見ましたか? https://dev.mysql.com/doc/connector-python/en/connector-python-example-connectinghtml – Greg0ry
あなたの質問を現在のサンプルとエラースタックで更新できますか? – Greg0ry
..... updated: –