最后,我想将主机输出到一个列表中
try:
cnx = mysql.connector.connect(user='root', password='passwd',
database='some_db')
cursor = cnx.cursor()
except mysql.connector.Error as err:
print("Something went wrong: {}".format(err))
retrieveQuery = ("SELECT host_name,product from server")
cursor.execute(retrieveQuery)
for host,prod in cursor:
print ("{},{}".format(host,prod))
结果看起来不错:[主机1,PowerEdge]
retrieveQuery = ("SELECT host_name from server")
cursor.execute(retrieveQuery)
for host in cursor:
print ("{}".format(host))
结果:(u'host1',)
为什么我看到(u’,)的代码相同,但只选择了一列? 非常感谢您的帮助
您的
cursor
行结果始终是tuple
类型,请尝试:或
相关问题 更多 >
编程相关推荐