这是我在Python代码:类型数据的
queryuniq = "SELECT COUNT(distinct src_ip), COUNT(distinct video_id)FROM video"
cur.execute(queryuniq)
uniq = []
uniq = cur.fetchall()
print uniq
ip = str(uniq[0])
video = str(uniq[1])
fd2.write("There are %d ip addresses and %d video in total" %(int(ip), int(video)))
这是 “uniq的” 可变我得到的值:
((2052L, 163581L),)
而且此错误消息:
fd2.write("There are %d ip addresses in total" %(int(ip)))
ValueError: invalid literal for int() with base 10: '((2052L,),)'
video = str(uniq[1])
IndexError: tuple index out of range
我只是简单地想要计算数据库中列中的不同项目,并在文件中打印INT值。
任何人都可以解释为什么SELECT命令返回奇怪的数据格式,如((2052L,163581L),)?不明白为什么数字后有一个“L”..
我该如何解决这个问题?非常感谢!
检查表中的数据,最有可能它包含奇怪格式的数据? –