我正在尝试通过python代码在mysql表的3列中插入3个数组列表,但我不断收到错误消息(1241'operand应该包含1列')。我不知道如何解决。
sample_text='E://ahmedrazatg.txt'
conn=pymysql.connect("localhost","root","root","wordnet",use_unicode=True, charset="utf8")
cursor=conn.cursor()
file = open(sample_text,'r')
arr=[]
surah=[]
verse=[]
var1="ahmedraza"
for line in file.readlines():
words=re.split(' |/|:|;|,|-RRB-|-LRB-|!|\*|\*\*|``',line)
words=[line.replace(".","") for line in words]
surah.append(words[0])
verse.append(words[2])
j=4
while j<len(words):
arr.append(words[j])
j+=2
sql="insert into cmp_translation1(surah_no,verse_no,translation,translator_id)values(%s,%s,%s,%s)"
data=surah,verse,arr,var1
r=cursor.execute(sql,data)
conn.commit()
cursor.close()
conn.close()
我的输入文件是这样的:
1|6|Guide us the straight way
2|63|And when We made a covenant with you
2|18|Deaf dumb blind and they cannot
我想要这样的输出:
translation_id|surah_no |verse_no |translation |translator_id
1 | 1 | 6 |Guide us the straight way |ahmedraza
2 | 2 | 63 |We made covenant with you |ahmedraza
3 | 2 | 18 |Deaf dumb blind cannot tu |ahmedraza