Python solves the Chinese garbled method in the Fedora Zip

Source: Internet
Author: User
Preface

Many times in Windows to compress the file is not a problem, but to Linux, there is garbled, very common. In the past under Ubuntu, `unzip -O GBK filename.zip` it can be done. After changing fedora, no garbled compressed files have been found for the time being. In the evening to download a book CD-ROM, and encountered garbled. The previous method did not succeed. Looked at the next unzip help, did not-o that parameter = = just find a way to solve with Python, share under.

To create a new '. py ' suffix file, copy and paste the code directly:

#!/usr/bin/env python#-*-coding:utf-8-*-import osimport sysimport 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.closefile.close ()

Execute unzip the zip file, the cute Chinese will come out.

Python file name. py file name to unzip. zip

Summarize

Well, the problem is so easy to solve, everyone has learned it? Hope this article to everyone's study or work can bring certain help, if there is doubt you can message exchange.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.