How to check empty gzip file in Python

后端 未结 8 905
太阳男子
太阳男子 2021-01-12 01:46

I don\'t want to use OS commands as that makes it is OS dependent.

This is available in tarfile, tarfile.is_tarfile(filename), to check if

8条回答
  •  心在旅途
    2021-01-12 02:20

    import gzip
    
    with gzip.open("pCSV.csv.gz", 'r') as f:
    
        f.seek(3)
        couterA = f.tell()
    
        f.seek(2,0)
        counterB = f.tell()
    
        if(couterA > counterB):
            print "NOT EMPTY"
        else:
            print "EMPTY"
    

    This should do it without reading the file.

提交回复
热议问题