I have a connection to my MySQL DB. And my program reads the Selected Objects and makes a tuple out of it (result)
a = """SELECT plates FROM plat"""
cursorO.execute(a)
connectionoracle.commit()
result = cursorO.fetchall()
print result
Now, I want to write the content of "result" into an other db. I try this:
s = result
cursorM.execute("""UPDATE `anpr_localhost`.`plat` SET
`Plat` = %s
WHERE `ID` = 1;""", (s))
connectionmysql.commit()
cursorM.close()
This is simply not working, because result is a tuple and not a string. I already tried
result.join(map(str, result), '.')
And different variations of this, but my Consule always tells me that tuple object has no function "join" and things like that.
How can I convert my tuple (result) to a normal string ?
Just join after you have mapped ".".join(map(str, result))
result =(1,2,3,4,)
print ".".join(map(str, result))
1.2.3.4
Or if a list of tuples:
" ".join(".".join(map(str, s)) for s in result)
If the result is a list of tuples, you can try to do the following:
results = [".".join(map(str,r)) for r in result]
print ".".join(results)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.