title: How do I confirm if a variable is in a csv file?
body: <p>I get this error when I run my code and reach the csv file part:
  line 96, in fieldnames
  self._fieldnames = next(self.reader)
  io.UnsupportedOperation: read</p>
  
  <p>My code:</p>
  
  <pre><code>import csv
  username = ""
  global enteruser
  global username
  
  def user():
      age  = input("What is your age:")
      year = input("What is your year group?")
      name = input("What is your name?")
      username = name+age+year
      return username
  
  def username_validator():
      with open('usernames.csv', 'ab') as file:
          reader = csv.DictReader(file)
          for row in reader:
              print(row)
              if  enteruser or username == row["usernames"]: # if the username shall be on column 3 (-&gt; index 2)
                  print ("is in file")
                  with open("user1.csv","ab") as quiz:
                      quizreader = csv.DictReader(quiz,delimiter=",")
                      for row in quizreader:
                          print(row["name"])
              else:
                  print("doesnt work")
  
  isuser = input("Do you have a username?")
  if isuser == ("yes" or "Yes"):
      enteruser = input("Enter username:")
      username_validator()
  elif isuser == ("no" or "No"):
     user()
  else:
      None
  
  print(username)  
  </code></pre>