0
I’m performing a select on DB with the Python and treating this return.
My doubt is in the use of a for
within other’s for
,
use the script below:
import mysql.connector
mydb = mysql.connector.connect(
user='root',
host='localhost',
password='***')
mycursor = mydb.cursor()
mycursor.execute("select calldate, clid, src, dst from cdr.cdr \
where calldate like '2019-02-18%'\
ORDER BY calldate desc limit 2")
myresult = mycursor.fetchall()
for row in myresult:
for fild in row:
print (fild[0])
print (fild[1])
print (fild[2])
print (fild[3])
mydb.close()
And the following error is being displayed:
# python3.6 dumpMysql.py
Traceback (most recent call last):
File "dumpMysql.py", line 18, in <module>
print (fild[0])
TypeError: 'datetime.datetime' object is not subscriptable
I’m trying to get the output
be it:
Primeira linha do select
campo0
campo1
campo2
campo3
Segunda linha do select
campo0
campo1
campo2
campo3
When you run the code, what is inside the "myresult" variable? What kind of object is allocated to it?
– Rafael Barros