title: Copy 'N' lines from one file to another in python?
body: <p>Essentially what I am attempting to do is read 'n' number of lines from a file and then write them to a separate file. This program essentially should take a file that has 100 lines and separate that file into 50 separate files. </p>
  
  <pre><code>def main():
       from itertools import islice
       userfile = raw_input("Please enter the file you wish to open\n(must be in this   directory): ")
       file1 = open(userfile, "r+")
       #print "Name: ", file1.name
       #print "Closed or not", file1.closed
       #print "Opening mode: ", file1.mode
       #print "Softspace flag: ", file1.softspace
       jcardtop = file1.read(221);
       #print jcardtop
       n = 2
       count = 0
       while True:
           next_n_lines = list(islice(file1,n))
           print next_n_lines
           count = count + 1
           fileout = open(str(count)+ ".txt", "w+")
           fileout.write(str(jcardtop))
           fileout.write(str(next_n_lines))
           fileout.close()
           break
           if not next_n_lines:
                break
  </code></pre>
  
  <p>I do have the file printing as well to show what is in the variable next_n_lines. </p>
  
  <pre><code>*['\n', "randomtext' more junk here\n"]
  </code></pre>
  
  <p>I would like it instead to look like</p>
  
  <pre><code> randomtext' more junk here
  </code></pre>
  
  <p>Is this a limitatoin of the islice function? Or am I missing a portion of the syntax? </p>
  
  <p>Thanks for your time!</p>