title: Reading first lines of bz2 files in python
body: <p>I am trying to extract 10'000 first lines from a bz2 file.</p>
  
  <pre><code>   import bz2       
     file = "file.bz2"
     file_10000 = "file.txt"
  
     output_file = codecs.open(file_10000,'w+','utf-8')
  
     source_file = bz2.open(file, "r")
     count = 0
     for line in source_file:
         count += 1
         if count &lt; 10000:
             output_file.writerow(line)
  </code></pre>
  
  <p>But I get an error "'module' object has no attribute 'open'". Do you have any ideas? Or may be I could save 10'000 first lines to a txt file in some other way? I am on Windows.</p>