[英]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. 我有一个Pyhton脚本,该脚本从本地MySql表中提取单元格值,但数据与String不同。
For example, mysql value = fromme@server.com 例如,mysql值= 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: 然后在我的execute函数中使用此变量,如下所示:
chat.main(['-c', chatTo, '-u', chatFrom, '-p', chatPass, '-m', chatMessage])
Now I want to make the variables dynamic by using the MySql table: 现在,我想使用MySql表使变量动态化:
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. 然后在完全相同的execute函数中使用它,但是我遇到的问题是,值在某种程度上是不同的。 Python is complaining about the use of the "@" in the value.
Python抱怨值中使用“ @”。 Before, it did not complain at all as I suppose it was because "chatTo" was originally a string so it did not matter.
以前,它根本没有抱怨,因为我想这是因为“ chatTo”最初是一个字符串,所以没关系。
So even if I use str(chatTo) python still complains about the @. 因此,即使我使用str(chatTo),python仍然会抱怨@。
The syntax of the execute command is as so: execute命令的语法如下:
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?
我应该如何编写,以使MySql游标与标准字符串相同?
cursor.fetchone()
always returns a tuple, even if there's only one element to return. 即使只有一个要返回的元素,
cursor.fetchone()
总是返回一个元组。 So your chatTo
variable is actually ('to@server.com',)
. 因此,您的
chatTo
变量实际上是('to@server.com',)
。
You would need to explicitly get the first element: 您将需要显式获取第一个元素:
chatTo = cursor.fetchone()[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.