python解决Fedora解压zip时中文乱码的方法
作者:daisy 时间:2021-06-02 09:23:09
前言
很多时候在windows下压缩文件没问题,但是到了Linux下,出现乱码,很常见。以前在Ubuntu下,用`unzip -O GBK filename.zip`
就可以搞定。 换了Fedora后,暂时没发现乱码的压缩文件。晚上下载一本书的光盘,又碰到了乱码。尝试之前的方法没成功。看了下unzip的help,没-O那个参数了== 刚好找到一个用python解决的办法,分享下。
新建一个`.py`后缀的文件,直接复制粘贴代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
print "Processing File " + sys.argv[1]
file=zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
utf8name=name.decode('gbk')
print "Extracting " + utf8name
pathname = os.path.dirname(utf8name)
if not os.path.exists(pathname) and pathname!= "":
os.makedirs(pathname)
data = file.read(name)
if not os.path.exists(utf8name):
fo = open(utf8name, "w")
fo.write(data)
fo.close
file.close()
执行解压zip文件,可爱的中文就出来了。
python 文件名.py 需要解压的文件名.zip
总结
好了,这个问题就这么简单的解决了,大家都学会了吗?希望这篇文章对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。
标签:python,fedora,解压,zip
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
pygame编写音乐播放器的实现代码示例
2021-08-12 18:08:48
![](https://img.aspxhome.com/file/2023/4/77924_0s.jpg)
Python实现base64编码的图片保存到本地功能示例
2024-01-01 22:58:03
![](https://img.aspxhome.com/file/2023/7/89207_0s.jpg)
Python详细讲解图像处理的而两种库OpenCV和Pillow
2022-08-14 05:23:19
![](https://img.aspxhome.com/file/2023/3/79493_0s.png)
Python实现向服务器请求压缩数据及解压缩数据的方法示例
2023-03-14 05:02:08
python脚本实现验证码识别
2022-02-03 09:41:30
![](https://img.aspxhome.com/file/2023/4/79664_0s.jpg)
PHP概率计算函数汇总
2023-11-19 08:06:19
Python实现为PDF大文件批量去除水印
2023-04-14 19:59:04
![](https://img.aspxhome.com/file/2023/0/69560_0s.png)
Python实现外星人去哪了小游戏详细代码
2023-08-07 13:42:44
微软开源最强Python自动化神器Playwright(不用写一行代码)
2024-01-02 00:38:00
![](https://img.aspxhome.com/file/2023/9/95419_0s.gif)
python七种方法判断字符串是否包含子串
2023-09-19 04:06:20
使用Python批量修改文件名的代码实例
2022-03-21 04:02:53
![](https://img.aspxhome.com/file/2023/0/80450_0s.png)
python超详细实现字体反爬流程
2022-08-30 22:39:03
![](https://img.aspxhome.com/file/2023/1/93541_0s.png)
python3 pillow生成简单验证码图片的示例
2022-08-16 23:17:05
python3 dict ndarray 存成json,并保留原数据精度的实例
2021-03-04 13:25:31
python生成以及打开json、csv和txt文件的实例
2023-08-05 10:44:49
python 基于Appium控制多设备并行执行
2022-12-11 12:00:06
python动态网站爬虫实战(requests+xpath+demjson+redis)
2023-03-30 20:01:51
![](https://img.aspxhome.com/file/2023/4/98784_0s.png)
企业网站FLASH引导页存在的意义
2008-06-04 11:09:00
python使用Faker进行随机数据生成
2023-12-21 14:24:33
![](https://img.aspxhome.com/file/2023/9/85129_0s.png)
PHP微信开发之有道翻译
2023-11-22 01:08:19