亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用Python將空格分隔的文本文件插入mysql?

如何使用Python將空格分隔的文本文件插入mysql?

Cats萌萌 2021-03-21 17:23:49
我的文本文件如下所示:10May2013   3.1   http://ncbi.org p.sojae_aafeatureimp    p.sojae_aafeatureimp10May2013   3.2   http://ncbi.org   p.sojae_aasequenceimp   p.sojae_aasequenceimp10May2013   3.3   http://ncbi.org   p.sojae_blatalignment   p.sojae_blatalignment如何解析這些單獨的行并將其插入到數據庫中?數據庫結構:(日期,版本,URL,名稱,描述)我必須使用Python將文本文件中的值插入mysql。到目前為止,我的腳本是這樣的:import MySQLdb, csv, syswith open('externaldatabase.txt') as textfile:  csvreader = csv.reader(textfile)  csvdata = []  for row in csvreader:  csvdata.append(row)conn = MySQLdb.connect (host = "localhost",user = "username", passwd = "password",db = "database_name")c = conn.cursor()for row in csvdata:# Insert a row of datac.execute("INSERT INTO externaldatabase (release_date, version, download_url, name, description) VALUES ('%s', '%s', '%s', '%s', '%s')" % (row))conn.commit()c.close()但它讓我出錯:Traceback (most recent call last):File "csv1.py", line 16, in <module>c.execute("INSERT INTO externaldatabase (release_date, version, download_url, name, description) VALUES ('%s', '%s', '%s', '%s', '%s')" % (row))TypeError: not enough arguments for format string
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 274 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號