0
我試圖通過Python 2.7更新MySQL表。我已閱讀並嘗試了許多解決方案,並不斷收到錯誤消息:類型錯誤:格式化錯誤「TypeError:並非在字符串格式化過程中轉換的所有參數」MySQLdb
import MySQLdb
import jellyfish
db = MySQLdb.connect('localhost','root','12badger12','group2')
cursor = db.cursor()
sql_com_dept = "SELECT id, bus_name FROM com_dept"
sql_tex = "SELECT company_name FROM tex"
score = 0
cursor.execute(sql_tex)
company_count = 10
while company_count >= 1:
tex_tup = cursor.fetchone()
company_name = tex_tup
company = str(company_name)
cursor.execute(sql_com_dept)
dept_count = 10
while dept_count >= 1:
dept_tup = cursor.fetchone()
dept_name = dept_tup
dept = str(dept_name)
lev = jellyfish.levenshtein_distance(dept, company)
jar = jellyfish.jaro_distance(dept, company)
dam = jellyfish.damerau_levenshtein_distance(dept, company)
score_in = (lev + jar + dam)/3
if score_in >= score:
base_name = dept
base_id = dept_id
score = score_in
else:
pass
dept_count = dept_count - 1
cursor.execute("UPDATE tex SET base_name = $s WHERE company_name = $s",
(base_name, company_name,))
db.commit()
company_count = company_count - 1
print company_count
cursor.close()
db.close()
print "Matching Complete!!!"
如何更新領域BASE_NAME字符串轉換的過程中不是所有的參數?
我是編程新手,非常感謝您的幫助。
謝謝。