[PYTHON] About Japanese path of pyminizip

What is pyminizip?

You can zip files with python. There is also `zipfile``` in the standard python library, but I can't put a password on zip. I wanted to set a password this time, so I tried using `pyminizip```.

My environment

It is windows10 (Pro). python is `` `Python 3.7.1```. It doesn't really matter. This article is for Windows users like me who continue to smoke the sweet honey of Microsoft. UNIX people do something on their own!

Installation

Just type the following command

pip install pyminizip

How do you use this

It's okay to write like this

test_zip.py


import pyminizip

pyminzip.compress(
    'Source file name',
    'Source file prefix',
    'Output file name.zip',
    'password',
    int(0)               #Compression rate: 0-9(0 is uncompressed)
)

1st argument: File name to be zipped 2nd argument: Directory where you want to put the file after zip compression Third argument: output file name Fourth argument: password Fifth argument: compression rate. You can specify 0-9. 0 is uncompressed

For example, if you execute pyminizip.compress ('src / src.txt','dir','output.zip','password', int (0))` ``, it will be in the place where it was executed. A zip file with `` dir / src.txt inside is output with the file name output.zip.

Main subject

If you are Japanese, there are times when you want to output in Japanese, such as the source file name or output file name, right? However, `` `pyminizip``` will give an error if you just throw a string normally. The error comes out as follows.

Traceback (most recent call last):
  File "test_zip.py", line 28, in <module>
    test1()
  File "test_zip.py", line 16, in test1
    int(0)
OSError: error in opening output/test.txt for reading

So, what to do is as follows.

test_zip.py


import pyminizip

pyminzip.compress(
    'Source file name'.encode('cp932'),
    'Source file prefix'.encode('cp932'),
    'Output file name.zip'.encode('cp932'),
    'password'.encode('cp932'),
    int(0)               #Compression rate: 0-9(0 is uncompressed)
)

If you change the character code to cp932, it will pass. Probably because Windows uses `` `cp932```.

Summary

I want to create a zip file with a password, but I can't do it with the standard library `zipfile```, so I tried to use pyminizip``` did. I hope it helps someone. It is also good to look back.

reference

pyminizip: Official guy

Recommended Posts

About Japanese path of pyminizip
About Japanese support of cometchat
[Linux] About PATH
About Japanese fonts of matplotlib (for Mac)
Linux (about directory path)
About all of numpy
About assignment of numpy.ndarray
About MultiIndex of pandas
About variable of chainer
Japanese localization of Pycharm
About max_iter of LogisticRegression () of scikit-learn
About the garbled Japanese part of pandas-profiling in Jupyter notebook
Japanese localization setting of PyCharm
About the ease of Python
About various encodings of Python 3
About all of numpy (2nd)
About cost calculation of MeCab
About approximate fractions of pi
Japanese translation of sysstat manual
About the components of Luigi
Japanese translation of Linux manual
About HOG output of Scikit-Image
About the features of Python
About data management of anvil-app-server
Japanese translation of the e2fsprogs manual
Get absolute path of running process
About the return value of pthread_mutex_init ()
About the return value of the histogram.
About the basic type of Go
Topic extraction of Japanese text 1 Basics
About the upper limit of threads-max
About circular crossover of genetic algorithms
Japanese translation of the man-db manual
Appropriate Japanese translation of pytorch tensor_tutorial
About the behavior of yield_per of SqlAlchemy
About import error of PyQt5.QtWidgets (Anaconda)
About the size of matplotlib points
About color halftone processing of images
Japanese translation of the util-linux manual
About the basics list of Python basics
Japanese translation of the iproute2 manual