前言
很多时候在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时中文乱码的方法相关文章请关注PHP中文网!

Pythonusesahybridmodelofcompilationandinterpretation: 1) thepythoninterpretercompilessourcodcecodeintoplatform-independentbytecode.2) thepythonvirtualmachine (PVM) thenexecutesthisbytecode, BalantingeaseOfusoWithperformance.

Pythonisbothinterpretedandandcompiled.1) it'scompiledtobytecodeforporabilityAcrossplatforms.2) theBytecodeistheninterpreted, membolehkanfordynamictypingandrapiddevelopment, walaupunItmayBeslowerLowerWanLelyCiledlanguages.

ForloopsareidealwhenyonesshenumberofiterationsationseSinadvance, whilewhileloopsarebetterforsituationshipheryouneedtoloopuntilaconditionismet.forloopsaremoreeficientablyandable, yang sesuai, manakala whileloopsoffermorecontrolandareusefereficeficeficeficeficient,

Forloopsareusedwhenthenumberofiterationsisknowninadvance, whilewhileloopsareusedwhenTheiterationsdependonacondition.1) forloopsareidealforiteratingoversequencesLikeListsorArrays.2)

Pythonisnotpurelyinterinterpreted; itusesahybridapproachofbytecodecompilationandruntimeinterpretation.1) pythoncompilessourcecodeintobytecode, whoomeSthenexecutedbythepythonvirtualmachine (pvm)

ToConcatenatelistsinpythonwiththesameelements, gunakan: 1) operatortokokduplicates, 2) asettoremoveduplicates, OR3) listomprehensionfensionfensionfensionfensiontroloverduplicates, setiapmethodhasdifferentperformanceAdordlications.

Pythonisaninterpretedlanguage, menawarkanfuseofuseandflexibilitybutfacingperpormancelimitationsincriticalapplications.1) interpretlanguagesepythonexecuteline-by-line, membolehkanMmediateDebackandrapidprototyping.2)

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

Video Face Swap
Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Artikel Panas

Alat panas

Notepad++7.3.1
Editor kod yang mudah digunakan dan percuma

SublimeText3 versi Cina
Versi Cina, sangat mudah digunakan

Hantar Studio 13.0.1
Persekitaran pembangunan bersepadu PHP yang berkuasa

SublimeText3 Linux versi baharu
SublimeText3 Linux versi terkini

Versi Mac WebStorm
Alat pembangunan JavaScript yang berguna
