python从指定文件夹减压GZ文件到指定文件夹
时间: 2023-07-10 15:03:19 浏览: 161
可以使用Python内置的gzip模块来解压.gz文件,具体步骤如下:
1. 导入gzip模块
```python
import gzip
```
2. 打开gz文件,并读取内容
```python
with gzip.open('/path/to/file.gz', 'rb') as f:
file_content = f.read()
```
其中,'/path/to/file.gz'为待解压的gz文件的路径,'rb'表示以二进制方式读取文件。
3. 将解压后的内容写入指定文件夹中的文件
```python
with open('/path/to/output_file', 'wb') as f:
f.write(file_content)
```
其中,'/path/to/output_file'为输出文件的路径。
完整代码如下:
```python
import gzip
with gzip.open('/path/to/file.gz', 'rb') as f:
file_content = f.read()
with open('/path/to/output_file', 'wb') as f:
f.write(file_content)
```
需要将上述代码中的路径替换为实际路径。
阅读全文
相关推荐

















