Big file compression with python

前端 未结 2 1204
不思量自难忘°
不思量自难忘° 2020-12-25 08:17

I want to compress big text files with python (I am talking about >20Gb files). I am not any how an expert so I tried to gather the info I found and the following seems to w

相关标签:
2条回答
  • 2020-12-25 08:35

    Your script seems correct, but can be abbreviated:

    from shutil import copyfileobj
    
    with open('bigInputfile.txt', 'rb') as input:
        with bz2.BZ2File('bigInputfile.txt.bz2', 'wb', compresslevel=9) as output:
            copyfileobj(input, output)
    
    0 讨论(0)
  • 2020-12-25 08:52

    Why are you calling the .close() methods? They are not needed as you use the with: statement.

    0 讨论(0)
提交回复
热议问题