第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Python 腳本 - mysql.connector 不更新 MariaDB 表

Python 腳本 - mysql.connector 不更新 MariaDB 表

我一直試圖弄清楚為什么我的 python 腳本沒(méi)有更新我的數(shù)據(jù)庫(kù)。我有一個(gè)名為的文件database.py,它的外觀如下:    import mysql.connector as mariadb    import globals    def connect():        mariadb_connection = mariadb.connect(user=globals.MY_USERNAME, password=globals.MY_PASSWORD, database='ellen')        return mariadb_connection    def insert_author_topics(author_id, topics, cursor):        sql = "UPDATE author SET topics = \'" + str(topics) + "\' WHERE id = " + str(author_id) + ";"        try:            cursor.execute(sql)        except mariadb.Error as error:             print("Error: {}".format(error))    def close(connection):       connection.commit()       connection.close()在我的主文件中,我有一個(gè)像這樣的函數(shù):def get_topics(x, ldamodel, cursor, connection):    author_text = x['processed_text']    bow_vector = dictionary.doc2bow([author_text])    topics = '['    for index, score in sorted(ldamodel[bow_vector], key=lambda tup: -1*tup[1]):        new_topic = "Score: {}\t Topic: {} ".format(score, ldamodel.print_topic(index, 5))        topics += new_topic    topics += ']'    database.insert_author_topics(author['id'], topics, cursor)    connection.commit()我有一個(gè) Pandas 數(shù)據(jù)框的作者和get_topics,它insert_author_topics會(huì)像這樣調(diào)用每個(gè)作者:authors.apply(lambda x: get_topics(x, ldamodel, cursor, connection), axis=1)我總共有大約 100,000 個(gè)作者。出于某種原因,每當(dāng)我運(yùn)行這個(gè)腳本時(shí),數(shù)據(jù)庫(kù)中只有大約 200 個(gè)作者更新。當(dāng)我嘗試運(yùn)行腳本時(shí),我沒(méi)有收到任何錯(cuò)誤。我嘗試打印出每個(gè)用 sql 語(yǔ)句更新的作者的 ID,我打印出大約 100,000 個(gè) ID。任何幫助,將不勝感激。如果需要,我可以提供更多信息。謝謝!
查看完整描述

1 回答

?
慕沐林林

TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊

問(wèn)題出在這行代碼中:

database.insert_author_topics(author['id'], topics, cursor)

如果你看看我傳遞給函數(shù)的參數(shù),我實(shí)際上應(yīng)該insert_author_topics像這樣調(diào)用:

database.insert_author_topics(x['id'], topics, cursor)

我不完全確定這是如何在不拋出任何錯(cuò)誤的情況下工作的,但很高興我終于弄明白了!


查看完整回答
反對(duì) 回復(fù) 2021-11-30
  • 1 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)