Answer the question
In order to leave comments, you need to log in
Python & MySQL | How to compare the received value from the request?
I can not compare the received value in any way.
I make a request like this:
db = MySQLdb.connect(host=**,user=**,passwd=**,db=**)
c = db.cursor()
c.execute("SELECT `status` AS TEXT FROM table ORDER BY id DESC LIMIT 1")
status = [item[0] for item in c.fetchall()]
print status
Answer the question
In order to leave comments, you need to log in
I solved this problem in this way:
after receiving, I translated the variable into a string
And now if status == "0" - it works without problems.
Thanks everyone for the replies.
Your status is a list of results. But since there is only one result, then your list contains only one element. The letter L means that your result is "long", but you do not need to write this L when comparing.
When you write if status == "[0L]", you are comparing status to the string "[0L]", not to the list containing element 0L.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question