简体   繁体   中英

Python difference between data

I have a Pyhton script that is pulling the cell value from the local MySql table but the data is not the same as a String.

For example, mysql value = fromme@server.com

My original working method which functioned just fine was written as so:

chatFrom = 'fromme@server.com'

then I used this variable in my execute function as so:

chat.main(['-c', chatTo, '-u', chatFrom, '-p', chatPass, '-m', chatMessage])

Now I want to make the variables dynamic by using the MySql table:

chatToCursor = (cursor.execute('SELECT value from configuration WHERE label = "chatTo"'))
chatTo = cursor.fetchone()

and then use it in the exact same execute function but the problem I am getting is that the values are not the same somehow. Python is complaining about the use of the "@" in the value. Before, it did not complain at all as I suppose it was because "chatTo" was originally a string so it did not matter.

So even if I use str(chatTo) python still complains about the @.

The syntax of the execute command is as so:

chat.main(['-c', 'to@server.com', '-u', 'user@server.com', '-p', 'pass', '-m', 'message'])

so in my variable is the single quote also that is messing me up. How should I write this so that the MySql cursor is the same as the standard string?

cursor.fetchone() always returns a tuple, even if there's only one element to return. So your chatTo variable is actually ('to@server.com',) .

You would need to explicitly get the first element:

chatTo = cursor.fetchone()[0]

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM