jupyter压缩文件中文乱码
时间: 2023-11-09 16:58:42 浏览: 182
java压缩zip文件中文乱码问题解决方法
jupyter压缩文件中文乱码的解决办法是先将文件名解码为cp437编码,然后再编码为gbk,并将文件名更名回原来的名称。下面是一种实现方式:
```python
import os
import zipfile
def fix_zip_filename(zip_filename):
is_zip = zipfile.is_zipfile(zip_filename)
if is_zip:
zip_file_contents = zipfile.ZipFile(zip_filename, 'r')
for file in zip_file_contents.namelist():
filename = file.encode('cp437').decode('gbk')
zip_file_contents.extract(file, os.path.dirname(zip_filename))
os.rename(os.path.join(os.path.dirname(zip_filename), file), os.path.join(os.path.dirname(zip_filename), filename))
zip_file_contents.close()
# 使用示例
zip_filename = 'jupyter.zip'
fix_zip_filename(zip_filename)
```
阅读全文