title: Why do I get a 'list index out of range' error here when creating an instance of a class?
body: <p>I have a text file with several tab-separated columns of information about articles from a blog. Each row in the file represents a single article, and by splitting a line up around the tabs, you can extract an ID number, a title, a paragraph and other things about that particular article.</p>
  
  <p>For example:</p>
  
  <pre><code>id   articleID    title    paragraph
  1    4    Motorola prototypes from Frog    Some cool looking concepts for phones...
  </code></pre>
  
  <p>So, I've written a piece of code which turns this into a list called <em>articlesFileList</em> where each line is an element in the list, and this works exactly as you'd expect.</p>
  
  <pre><code>file = open("articles.txt", "r", encoding="utf-8")
  file.readline() # (Skip first line)
  articlesFile = file.read()
  articlesFileList = articlesFile.split("\n")
  </code></pre>
  
  <p>After this, I then split the lines into their individual columns and create <em>Article</em> instances which have attributes for the id, title, paragraph etc.</p>
  
  <p><code>for line in articlesFileList:
      columns = line.split("\t")
      article = Article(columns[0], columns[2], columns[3])
      articleList = []
      articleList.append(article)</code></p>
  
  <p>But this code then throws this error:</p>
  
  <pre><code> Traceback (most recent call last):
   File "E:\Python\RBTrends\RBTrendsAnalysis.py", line 55, in &lt;module&gt;
   articlesList = createArticles(articlesFileList)
   File "E:\Python\RBTrends\RBTrendsAnalysis.py", line 32, in createArticles
   article = Article(columns[0], columns[2], columns[3])
   IndexError: list index out of range
  </code></pre>
  
  <p>My first thought was that maybe the <em>columns</em> list didn't contain the correct information, so I added the following code to check what was in that list:</p>
  
  <pre><code>for i in columns:
      print(i)
  </code></pre>
  
  <p>...and the list appears absolutely perfect. Each column of each line is printed correctly. I've even tried to print each index of the list just to see if they could be accessed 'by hand', and they can. The program with accessing the list elements seems to just be when creating instances of a class.</p>
  
  <p>Any help/explanation would be very much appreciated as this is an error that has been confusing me for a while now.</p>