python解压并另存 .bz2文件的方法
生活随笔
收集整理的這篇文章主要介紹了
python解压并另存 .bz2文件的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python解壓并另存 .bz2文件的方法
我們在進行數據處理的過程中有可能會遇到.bz2文件,對此我們可以先對壓縮文件進行,然后轉存為非壓縮文件,再進行讀取與處理。 import os import bz2 # f is the .bz2 file, # for example xxxx.bz2 zipfile = bz2.BZ2File(f) # open the file data = zipfile.read() # get the decompressed data newfilepath = f[:-4] # assuming the filepath ends with .bz2 open(newfilepath, 'wb').write(data) # write a uncompressed file
總結
以上是生活随笔為你收集整理的python解压并另存 .bz2文件的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 废弃,PHP 7 废弃特性
- 下一篇: python task done_pyt