title: IndexError: string index out of range - I cannot find answer anywhere but seems so easy
body: <p>I'm using python 3.4</p>
  
  <p>I have a .txt file and each line starts with an id number, then is followed by letters and numbers, for example...</p>
  
  <pre><code>012394  The big Project 1997 June Terry Smith
  013894  Toms Project   1994 March Michaal Bach
  </code></pre>
  
  <p>and so on... I need to copy all lines that start with 01 to another file</p>
  
  <p>when I use the following it keeps giving me the above error:</p>
  
  <pre><code>with open("old.txt","r") as mf, open("new.txt","w") as nf:
  
      def dafunction():
          mf = open ("old.txt", "r")
          nf = open("new.txt","w")
          for line in mf:
              bat = str(line)
              if bat.startswith(01):
                  nf.write(line)
  
  
  
  dafunction()
  mf.close()
  nf.close()
  </code></pre>
  
  <p>I've tried using bat.startswith("01) and skipping setting bat variable and going straight to line.startswith(01), etc. and I keep getting the error.</p>
  
  <p>Does anyone know what I'm doing wrong? or another way to accomplish objective?</p>
  
  <p>Any help is greatly appreciated!</p>