title: Reading text and assigning a class to data in Python
body: <p>I've been searching around, and had no luck finding anything answering my question. </p>
  
  <p>Essentially I have a file with the following data:</p>
  
  <pre><code>Title - 19
  Artist - Adele 
  Year released - 2008
  1 - Daydreamer, 3:41, 1
  2 - Best for Last, 4:19, 5
  3 - Chasing Pavements, 3:31, 7
  4 - Cold Shoulder, 3:12, 3
  
  Title - El Camino 
  Artist - The Black Keys 
  Year released - 2011 
  1 - Lonely Boy, 3:13, 1 
  2 - Run Right Back, 3:17, 10 
  
  EOF 
  </code></pre>
  
  <p>I know how to create classes, and how to assign an object to a class and values to that object, but I am just about ready to tear my hair out on how it is I'm supposed to process the text. From text, I need to create a title for the album, and assign the album's information to it. There's more else besides that needs to be done, and there are more lines to be read, and I just don't know where to start on this. I've found two "album.py" files via google, and I've been unable to make heads or tails of how to apply the solution to my case. </p>
  
  <p>And yes, this is for a school assignment. I've done some digging around and found some things relevant, but I'm just not understanding it. I'm new to programming in general, and I've made progress but this seems too far over my head.</p>
  
  <p>I know I could reduce this to lists using split (\n\n) and operating on a series of progressively smaller lists, but I am trying to avoid this method at all costs.</p>
  
  <p>EDIT:</p>
  
  <p>For the time being, it's best to assume I know nothing. Though, to answer below question: I can open the file and read it. If its a consistent CSV formatted file, I can write code to process the enclosed data, and create a class structure that uses that data. Right now I'm just having trouble with the first three lines, and the digits immediately below.</p>
  
  <p>APRIL 4 2012:</p>
  
  <p>Okay, I have some code, I've left the comments with respect to it underneath.</p>
  
  <pre><code>def getInput():
      global albums
      raw = open("album.txt","r")
      infile = raw
      raw.close
      text=""
      line = infile.readline()
      while (line != "EOF\n" ):
          text += line
          line=infile.readline()
      text=text.rstrip("\n\n")
      albums=[str(n) for n in text.split("\n\n")]
      return albums
  
  
  class Album():
      def __init__(self, title, artist, date):
          self.title=title
          self.artist=artist
          self.date=date
          self.track={}
  
      def addSong(self, TrackID, title, time, ranking):
          self.track+={self}
  
      def getAlbumLength(self):
          asdf=0
      def getRanking(self):
          asdf=0
  
  def labels(x): #establishes labels per item to be used for Album Classifier
      title=""
      artist=""
      date=""
  
      for i in range(0,len(albums),1):
          sublist=[str(n) for n in albums[i].split("\n")]
          RANDUMB=len(albums[i])
          title=sublist[0]
          artist=sublist[1]
          date=sublist[2]
  
          for j in range(0,len(sublist),1):                
              song_info = [str(k) for k in sublist[3:].split("," and " - ")]
              TrackID=song_info[0]
              title=song_info[1]
              time=song_info[2]
              ranking=song_info[3]
  
  getInput()
  labels(albums)
  </code></pre>
  
  <p>Personal comments on code:
  I was trying to avoid getting it into lists because I anticipated this problem. As the functions are concerned, I have to use every single bloody one, because it's in the assignment requirements... I am displeased because I could probably get around using them. The code is working sufficiently enough, except for the last part of it where I am trying to take the song information. I want to split the song information into lists, which are nested into the album information list. Something like:</p>
  
  <pre><code>[Album title, Artist, Date released,[01,Song,3:44,2],[02,Song,0:01,9]....]
  </code></pre>
  
  <p>The current code gives me index out of range error as of right now... I am using python3.</p>
  
  <p>TLDR: The substance of my problem has thus changed from one of trying to solve how to go about starting the solution to how to take items in a list and convert them into nested lists.</p>