1

I want to read gzip and update the content.

However, I get the error

'AttributeError: 'GzipFile' object has no attribute 'extrastart''.

import gzip                                                 

with gzip.open("PhoneWindowManager.java.gz", "w+") as file: 
    for line in file:                                       
        if "setHdmiPlugged" in line:                        
            call = "#setHdmiPlugged"                        
            if call in line:                                
                continue                                    
            else:                                           
                print line                                  
                break   
Cœur
  • 37,241
  • 25
  • 195
  • 267
500004dolkong
  • 725
  • 3
  • 12
  • 19

1 Answers1

2

extrastart is only set if mode starts with 'r',

with gzip.open("PhoneWindowManager.java.gz", "r") as file://change "w+" to "r+" 
Eric Tsui
  • 1,924
  • 12
  • 21
  • Thanks for your advice. Additionally, I want to update some parts of the gzip file. To do this, I think I need to open the file with w+. Are there any other approaches? – 500004dolkong Jun 29 '15 at 06:09
  • There's no way to do that with python zipfile module. You have to create a new zip file and recompress everything again from the first file, plus the new modified file. please refer to http://stackoverflow.com/questions/4653768/overwriting-file-in-ziparchive – Eric Tsui Jun 29 '15 at 07:30
  • Please refer to [overwriting file in ziparchive](http://stackoverflow.com/questions/4653768/overwriting-file-in-ziparchive) and [How do I delete or replace a file in a zip archive?](http://stackoverflow.com/questions/13917340/how-do-i-delete-or-replace-a-file-in-a-zip-archive). Hope it helps. – Eric Tsui Jun 29 '15 at 07:36