user1726453
user1726453

Reputation: 51

how to store tuple value as python variable

I am fetching mysql select statement as a tuple. How do I extract 0 or 1 from the 2nd value? Here is the code.

records = cursor.fetchall()
print(records)
('billtest1407337726531', '\x00')
records1 = curson.fetchall()
print(records1)
('billtest1407337726531', '\x01')

I need to store the value 0 or 1 from above tuples records and records1

I tried as below but it isn't working.

for row in records
   print(row[1])
   print((tuple(row[1:1]))

Upvotes: 1

Views: 580

Answers (1)

John Zwinck
John Zwinck

Reputation: 249592

You want ord(records[1]) to take the second value and convert it from a string to an integer (not parse, just convert the byte).

Upvotes: 1

Related Questions