title: IndexError: list index out of range [Python]
body: <p>I've got this piece of code that calculates both the MD5 and SHA1 value of a given file and presents it in the console. It does its job, however i get the error message:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\Program Files (x86)\Aptana\workspace\Ipfit5\Semi-Definitief\test6.py",
  line 64, in &lt;module&gt;
  hash_file(woord)
  File "C:\Program Files (x86)\Aptana\workspace\Ipfit5\Semi-Definitief\test6.py",
  line 29, in hash_file
  hash_file(sys.argv[1]);
  IndexError: list index out of range
  </code></pre>
  
  <p>the code looks as following:</p>
  
  <pre><code>import sys, hashlib, os
  
  def hash_file(filename):    #Calculate MD5 and SHA1 hash values of a given file
  
   # Create hash objects for MD5 and SHA1.
   md5_hash = hashlib.md5()
   sha1_hash = hashlib.sha1()
   filename = r"C:/this.png"
  
   # Read the given file by 2K blocks. Feed blocks
   # into into the hash objects by "update(data)" method.
   fp = open(filename,'rb')
   while 1:
       data = fp.read(2048)
       if not data:
           break
       else:
           md5_hash.update(data)
           sha1_hash.update(data)
           fp.close()
           print "The MD5  hash of your file is" 
           print filename,":", md5_hash.hexdigest();
           print "The SHA1 hash of your file is" 
           print filename,":", sha1_hash.hexdigest();
           if __name__ == '__main__':
               hash_file(sys.argv[1]);
  
  hash_file(woord)
  </code></pre>
  
  <p>I call the function for (woord) because that is something defined later on in the script, but it is basically the same image as filename in the function hash_file(filename).</p>
  
  <p>Why do i get this error when it does show me both the hash values and how do i get rid of it ?</p>
  
  <p>EDIT: I know it has somethin to do with the  if <strong>name</strong> == '<strong>main</strong>':
                   hash_file(sys.argv[1]); but i can't figure it out. </p>
  
  <p>Any help is greatly appreciated</p>