title: Access the first column in each row in a list Python
body: <p>I have the following code in which the comments explain the output and desired output. I don't seem to be able to access (or understand the logic) behind how to access different fields in the list. </p>
  
  <pre><code>def viewrecs(username):
      username = (username + ".txt")
      with open(username,"r") as f:
        fReader=csv.reader(f)
        for row in fReader:
  
           for field in row:
  
              #print(field) #this prints everything in the file
              #print(row) #this also prints everything in the file
              #print(row[0])  #this also prints everything!!!!!!
              #print(field[0]) #this prints the first ELEMENT in each row, namely the "["
              #How do I access the first field of each column (the genre, like SCI-FI, or Romance)
  </code></pre>
  
  <p>The file in question is a text file based on the user's username. The contents are:</p>
  
  <pre><code>"['Sci-Fi', 'Blade Runner']"
  "['Sci-Fi', 'Star Trek']"
  "['Sci-Fi', 'Solaris']"
  "['Sci-Fi', 'Cosmos']"
  "['Drama', ' The English Patient']"
  "['Sci-Fi', 'Out of the Silent Planet']"
  "['Drama', ' The Pursuit of Happiness']"
  "['Drama', ' The English Patient']"
  "['Drama', ' Benhur']"
  "['Drama', ' Benhur']"
  </code></pre>
  
  <p>An answer as to how to access the column field (e.g. Sci-Fi, Drama etc) AND an explanation would be much appreciated.</p>
  
  <p>I want to print the entire first column ....i.e SCI-FI, SCI-FI, SCI-FI, DRAMA etc.....I need these to be read into a list ideally so they can be manipulated inside of the list</p>
  
  <p>Based on one of the answers below, IF the problem is regarding the way the data has been written to the file in the first place, the code /function that writes this data to the file is below:</p>
  
  <pre><code>def viewfilmfunction(x,username):
     #open the file as student file (variable)
     print(username, ":You are about to view Film:", x, "Enter the selection     ID number of the film again to confirm viewing")
     with open("films.txt","r") as filmsfile:
          #prompt the user to enter the ID number they require
          idnumber=input("Enter the ID number you require:")
          #call upon our reader (this allows us to work with our file)
          filmsfileReader=csv.reader(filmsfile)
          #for each row that is read by the Reader    
          for row in filmsfileReader:
              #and for each field in that row (this does it automatically for us)
              for field in row:
                  #if the field is equal to the id number that is being searched for
                  if field ==idnumber:
                      #print the row fields (genre and title) corresponding to that ID number
                     #create a list which contains the relevant fields in the row.
                    viewedlist=[row[1],row[2]]
                    print("You have viewed:", viewedlist)
     with open("fakeflixfile.txt","r")as membersfile:
        #Open Reader
              membersfileReader=csv.reader(membersfile)
              for row in membersfileReader:              
                 for field in row:
                    if field==username:
  
                       #Open Writer to append to file -this time it looks for the file stored by that username
                       with open("%s.txt" % username,"a") as membersfile:
  
                          membersfileWriter=csv.writer(membersfile)
                          #Use the writer to append the viewedlist to the appropriate member's user file. 
                          membersfileWriter.writerow([viewedlist])
  </code></pre>
  
  <p>FAKEFLIXFILE.txt contents</p>
  
  <p><code>username13022,Username@123,user,name1,2/02/3022,user Road,US455P,Mle,Nothing,username1@hotmail.com
      AugustineSalins1900.txt,Augstine@123,Augustine,Salins,5/02/1900,Hutchins  Road,CRBBAAA,Male,Theology,augustine@hotmail.com
      JosieBletchway3333,Bb@123,Josie,Bletchway,29/02/3333,Bletch Park,BB44AA,Female,Encryption,blecth@hotmail.com
      JoeBloggs.0.0,Joe@Bloggs12,Joe,Bloggs,0.0.0.0,0 Road,00000,Male,Joe Blogs,joe@hotmail.com</code></p>
  
  <p>UPDATE:
  I have now changed the txt file (based on username) so that the output generated doesn't produce a list:</p>
  
  <pre><code>Drama, The English Patient
  
  Drama, Benhur
  
  Sci-Fi,Cosmos
  </code></pre>
  
  <p>However, on running:</p>
  
  <pre><code>def viewrecs(username):
     #pass
     username = (username + ".txt")
     with open(username,"r") as f:
            fReader=csv.reader(f)
            for row in fReader:
               print(eval(row)[0])
  </code></pre>
  
  <p>The error persists:</p>
  
  <pre><code>    print(eval(row)[0])
      TypeError: eval() arg 1 must be a string, bytes or code object
  </code></pre>