0

I am trying to run some code that will get data from a website(ques) and compare it to a CSV(ans) file to get a result.

def ans(ques):
    ans = False
    csvfile = open('database.csv', 'r')
    reader = csv.reader(csvfile, delimiter=',')
    for row in reader:
        if ques == row[0]:
            ans = row[1]
            break
        if ques == row[1]:
            ans = row[0]
            break
    return(ans)

CSV file:

QUESTION,ANSWER
1+1=?,It's 2

When i run this code i get this:

UnicodeWarning: Unicode equal comparison failed to convert both arguments to 
Unicode - interpreting them as being unequal

However when i remove the ' it works as expected. Any help?

  • And what's the parameter `ques`? – user202729 Mar 11 '18 at 02:04
  • ques is the data that is scraped from the web page. In this case, it is "It's 2" i am working back from the answer to find the question it belongs to. –  Mar 11 '18 at 02:11
  • See this [asnwer](https://stackoverflow.com/questions/18193305/python-unicode-equal-comparison-failed) – Chiheb Nexus Mar 11 '18 at 02:16
  • Possible duplicate of [Python unicode equal comparison failed](https://stackoverflow.com/questions/18193305/python-unicode-equal-comparison-failed) – lenz Mar 11 '18 at 18:49
  • As far as I know, this warning doesn't exist in Python 3. It looks like you are using Python 2.x, and the linked post above applies. – lenz Mar 11 '18 at 18:54

0 Answers0