{"id":2070,"date":"2019-06-17T21:01:10","date_gmt":"2019-06-17T12:01:10","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=2070"},"modified":"2020-02-08T17:46:17","modified_gmt":"2020-02-08T08:46:17","slug":"python%e3%81%a7zip%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e5%9c%a7%e7%b8%ae%e3%83%bb%e8%a7%a3%e5%87%8d","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/2070","title":{"rendered":"Python\u3067ZIP\u30d5\u30a1\u30a4\u30eb\u3092\u5727\u7e2e\u30fb\u89e3\u51cd"},"content":{"rendered":"<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306fPython\u3067ZIP\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>zip\u5f62\u5f0f\u3067\u5727\u7e2e\u3059\u308b<\/h2>\n<p>Python\u3067ZIP\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u306b\u306f\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0d\u8981\u3067\u6a19\u6e96\u306ezipfile\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u64cd\u4f5c\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/docs.python.org\/ja\/3\/library\/zipfile.html#module-zipfile\">https:\/\/docs.python.org\/ja\/3\/library\/zipfile.html#module-zipfile<\/a><\/p>\n<h3>\u30d5\u30a1\u30a4\u30eb\u3092\u5727\u7e2e\u3059\u308b<\/h3>\n<p>\u307e\u305a\u306f\u7c21\u5358\u306a\u30b5\u30f3\u30d7\u30eb\u304b\u3089\u3001\u4e00\u3064\u306e\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092zip\u30d5\u30a1\u30a4\u30eb\u306b\u5727\u7e2e\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'w')as zf:\r\n    zf.write('data\/sample1.txt')\r\n\r\n<\/pre>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306fdata\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u914d\u4e0b\u306esample1.txt\u3068\u3044\u3046\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u3001sample.zip\u3068\u3044\u3046zip\u30d5\u30a1\u30a4\u30eb\u306b\u5727\u7e2e\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>zipfile.ZipFile\u30af\u30e9\u30b9\u306e\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u7b2c\uff11\u5f15\u6570\u3067\u6307\u5b9a\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u5165\u51fa\u529b\u64cd\u4f5c\u304c\u53ef\u80fd\u3067\u3059\u3002\u307e\u305f\u3001\u7b2c\uff12\u5f15\u6570\u3067\u30d5\u30a1\u30a4\u30eb\u30aa\u30fc\u30d7\u30f3\u30e2\u30fc\u30c9\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u66f8\u304d\u8fbc\u307f\u306a\u306e\u3067'w'\u3092\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u65e2\u5b58\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u5834\u5408\u306f'r'\u3092\u3001\u8ffd\u8a18\u3059\u308b\u5834\u5408\u306f'a'\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u5185\u306ewrite\u30e1\u30bd\u30c3\u30c9\u3067\u5727\u7e2e\u3059\u308b\u5bfe\u8c61\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002write\u30e1\u30bd\u30c3\u30c9\u306earcname\u3092\u6307\u5b9a\u3059\u308b\u3068zip\u30d5\u30a1\u30a4\u30eb\u5185\u90e8\u3067\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'w')as zf:\r\n    zf.write('data\/sample1.txt', arcname='sample1.txt')\r\n\r\n<\/pre>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u6700\u521d\u306e\u30b5\u30f3\u30d7\u30eb\u3068\u540c\u69d8\u3001data\/sample1.txt\u3092\u5727\u7e2e\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u76f4\u4e0b\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>\u8907\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u5727\u7e2e\u3059\u308b<\/h3>\n<p>\u5148\u7a0b\u306f\u30d5\u30a1\u30a4\u30eb\u3092\uff11\u3064\u3060\u3051\u5727\u7e2e\u3057\u307e\u3057\u305f\u304c\u3001\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u5185\u3067\u5727\u7e2e\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u8907\u6570\u30d5\u30a1\u30a4\u30eb\u3092zip\u306b\u5727\u7e2e\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'w')as zf:\r\n    zf.write('data\/sample1.txt')\r\n    zf.write('data\/sample2.txt')\r\n    zf.write('data\/sample3.txt')\r\n\r\n<\/pre>\n<h3>\u65e2\u5b58\u306eZIP\u30d5\u30a1\u30a4\u30eb\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u8ffd\u52a0\u3059\u308b<\/h3>\n<p>\u307e\u305f\u3001zipfile\u3067\u958b\u3044\u305f\u30d5\u30a1\u30a4\u30eb\u306f\u65b0\u305f\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u5148\u8ff0\u306e\u901a\u308a\u30d5\u30a1\u30a4\u30eb\u30aa\u30fc\u30d7\u30f3\u30e2\u30fc\u30c9\u306b\u8ffd\u8a18\u306e'a'\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u5185\u3067\u30d5\u30a1\u30a4\u30eb\u306e\u8ffd\u52a0\u304c\u53ef\u80fd\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'a')as zf:\r\n    zf.write('data\/sample4.txt')\r\n    zf.write('data\/sample5.txt')\r\n\r\n<\/pre>\n<h3>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3054\u3068\u5727\u7e2e\u3059\u308b<\/h3>\n<p>Python\u306e\u6a19\u6e96\u30e2\u30b8\u30e5\u30fc\u30ebos\u3092\u4f7f\u7528\u3059\u308b\u3068\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u914d\u4e0b\u306e\u30d1\u30b9\u30c4\u30ea\u30fc\u3092\u69cb\u7bc9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u306e\u3067\u3001\u5148\u7a0b\u306e\u30b5\u30f3\u30d7\u30eb\u306b\u6d41\u3057\u8fbc\u3081\u3070\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3054\u3068\u5727\u7e2e\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u6a19\u6e96\u30e2\u30b8\u30e5\u30fc\u30eb\u306eshutil\uff08\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306e\u6a5f\u80fd\u3092\u63d0\u4f9b\u3059\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\uff09\u304c\u540c\u69d8\u306e\u51e6\u7406\u3092\u63d0\u4f9b\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u3053\u3061\u3089\u3092\u4f7f\u7528\u3059\u308b\u65b9\u304c\u697d\u3067\u3057\u3087\u3046\u3002<\/p>\n<p><a href=\"https:\/\/docs.python.org\/ja\/3\/library\/shutil.html#shutil.make_archive\">https:\/\/docs.python.org\/ja\/3\/library\/shutil.html#shutil.make_archive<\/a><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport shutil\r\n\r\nshutil.make_archive('dir_sample', 'zip', root_dir='data\/sample_dir')\r\n<\/pre>\n<p>make_archive\u30e1\u30bd\u30c3\u30c9\u306f\u30d1\u30e9\u30e1\u30fc\u30bf\u3068\u3057\u3066\u4ee5\u4e0b\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>shutil.make_archive(base_name, format, [root_dir, [base_dir]])<\/p>\n<p>base_name\u306b\u4f5c\u6210\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u6307\u5b9a\u3057\u307e\u3059\u304c\u3001\u62e1\u5f35\u5b50\u306f\u7701\u7565\u3057\u307e\u3059\u3002format\u306b\u306f\u30a2\u30fc\u30ab\u30a4\u30d6\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3068\u3057\u3066'zip'\u3092\u6307\u5b9a\u3057\u307e\u3059\u304c\u3001zip\u4ee5\u5916\u306btar\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u307e\u305f\u3001\u4efb\u610f\u3067root_dir\u3001base_dir\u306e\u6307\u5b9a\u304c\u53ef\u80fd\u3067\u3001\u5727\u7e2e\u3059\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u30eb\u30fc\u30c8\u3068root_dir\u304b\u3089\u306e\u76f8\u5bfe\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u7701\u7565\u3057\u305f\u5834\u5408\u306f\u30ab\u30ec\u30f3\u30c8\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u304c\u6307\u5b9a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h2>zip\u30d5\u30a1\u30a4\u30eb\u3092\u89e3\u51cd\u3059\u308b<\/h2>\n<p>zip\u30d5\u30a1\u30a4\u30eb\u3092\u89e3\u51cd\u3057\u305f\u308a\u3001\u4e2d\u8eab\u3092\u53c2\u7167\u3059\u308b\u5834\u5408\u306f\u30d5\u30a1\u30a4\u30eb\u306e\u30aa\u30fc\u30d7\u30f3\u30e2\u30fc\u30c9\u306b'r'\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h3>\u89e3\u51cd\u3059\u308b<\/h3>\n<p>\u30aa\u30fc\u30d7\u30f3\u30e2\u30fc\u30c9\u306b'r'\u3092\u6307\u5b9a\u3057\u3066\u958b\u304d\u3001extractall\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'r')as zf:\r\n    zf.extractall('.\/output\/')\r\n<\/pre>\n<p>\u5f15\u6570\u306b\u89e3\u51cd\u5148\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u5834\u5408\u3001.\/output\/\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u914d\u4e0b\u306b\u89e3\u51cd\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001extract\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u500b\u5225\u306b\u89e3\u51cd\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'r')as zf:\r\n    zf.extract('data\/sample1.txt', '.\/output\/')\r\n<\/pre>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u306e\u5834\u5408\u3001data\/sample1.txt\u306e\u307f\u304c.\/output\/\u914d\u4e0b\u306b\u89e3\u51cd\u3055\u308c\u307e\u3059\u3002\u307e\u305f\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u6709\u7121\u3092\u78ba\u8a8d\u3057\u305f\u3044\u5834\u5408\u306f\u6b21\u306b\u8aac\u660e\u3059\u308b\u30d5\u30a3\u30a2\u30eb\u30ea\u30b9\u30c8\u306e\u53d6\u5f97\u3067\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<h3>\u89e3\u51cd\u3057\u306a\u3044\u3067\u4e2d\u8eab\u3092\u78ba\u8a8d\u3059\u308b<\/h3>\n<p>\u30aa\u30fc\u30d7\u30f3\u30e2\u30fc\u30c9\u306b'r'\u3092\u6307\u5b9a\u3057\u3066\u958b\u304d\u3001namelist\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u30ea\u30b9\u30c8\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'r')as zf:\r\n    print(zf.namelist()) # ['data\/sample1.txt', 'data\/sample2.txt', 'data\/sample3.txt']\r\n\r\n<\/pre>\n<h2>\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304d\u306ezip\u3092\u89e3\u51cd\u3059\u308b<\/h2>\n<p>extractall\u3001extract\u3067\u5f15\u6570pwd\u3067\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u6307\u5b9a\u3059\u308b\u3068\u30d1\u30b9\u30ef\u30fc\u30c9\u4ed8\u304dzipfile\u3092\u89e3\u51cd\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u30d1\u30b9\u30ef\u30fc\u30c9\u306f\u4ee5\u4e0b\u30b5\u30f3\u30d7\u30eb\u306e\u3088\u3046\u306bbyte\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nwith zipfile.ZipFile('sample.zip', 'r')as zf:\r\n    zf.extractall('.\/output\/', pwd=b'\u30d1\u30b9\u30ef\u30fc\u30c9')\r\n\r\nwith zipfile.ZipFile('sample.zip', 'r')as zf:\r\n    zf.extract('data\/sample1.txt', '.\/output\/', pwd=b'\u30d1\u30b9\u30ef\u30fc\u30c9')\r\n<\/pre>\n<p>\u4e00\u65b9\u3067Python3.7\u306e\u6642\u70b9\u3067\u5727\u7e2e\u6642\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u306f\u6b8b\u5ff5\u306a\u304c\u3089\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<div class=\"inyoumodoki\">\n It supports decryption of encrypted files in ZIP archives, but it currently cannot create an encrypted file.<br \/>\n<a href=\"https:\/\/docs.python.org\/3\/library\/zipfile.html#module-zipfile\">https:\/\/docs.python.org\/3\/library\/zipfile.html#module-zipfile<\/a>\n<\/div>\n<p>\u4ee3\u6848\u3068\u3057\u3066\u4ee5\u4e0b\u306e\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u88fd\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u624b\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/pypi.org\/project\/pyminizip\/\">https:\/\/pypi.org\/project\/pyminizip\/<\/a><\/p>\n<p>\u3082\u3046\u4e00\u3064\u6ce8\u610f\u70b9\u3067\u3059\u304c\u3001\u6697\u53f7\u5316zipfile\u306e\u89e3\u51cd\u306fC\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u306f\u306a\u304fPython\u3067\u8a18\u8ff0\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u300c\u975e\u5e38\u306b\u9045\u3044\u300d\u3067\u3059\u3002\u5927\u91cf\u306b\u51e6\u7406\u3059\u308b\u5834\u5408\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<div class=\"inyoumodoki\">\nDecryption is extremely slow as it is implemented in native Python rather than C.<br \/>\n<a href=\"https:\/\/docs.python.org\/3\/library\/zipfile.html#module-zipfile\">https:\/\/docs.python.org\/3\/library\/zipfile.html#module-zipfile<\/a>\n<\/div>\n<h2>zipfile\u306e\u7834\u640d\u3068crc32<\/h2>\n<p>\u4e00\u901a\u308a\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u3002\u6700\u5f8c\u306b\u696d\u52d9\u3067\u4f7f\u7528\u3059\u308b\u5834\u5408\u306e\u6ce8\u610f\u70b9\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<br \/>\n<br \/>\n\u30b7\u30b9\u30c6\u30e0\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3063\u3066\u3044\u3066\u554f\u984c\u306b\u306a\u308b\u306e\u304c\u30d5\u30a1\u30a4\u30eb\u306e\u7834\u640d\u3067\u3059\u3002\u5927\u91cf\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3063\u3066\u3044\u308b\u3068\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u306e\u30a8\u30e9\u30fc\u3001\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u306e\u30c7\u30a3\u30b9\u30af\u306e\u640d\u50b7\u3001\u8ee2\u9001\u6642\u306e\u30a8\u30e9\u30fc\u306a\u3069\u69d8\u3005\u306a\u7406\u7531\u3067\u30d5\u30a1\u30a4\u30eb\u306e\u7834\u640d\u304c\u767a\u751f\u3057\u307e\u3059\u306e\u3067\u7279\u306b\u53d7\u8a17\u958b\u767a\u306e\u5834\u5408\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>ZIP\u30d5\u30a1\u30a4\u30eb\u306e\u7834\u640d\u306e\u30c1\u30a7\u30c3\u30af\u6cd5\u3067\u3059\u304c\u3001\u30d5\u30a1\u30a4\u30eb\u30d8\u30c3\u30c0\u306e\u30aa\u30d5\u30bb\u30c3\u30c814\u756a\u76ee\u4ee5\u964d\u306b\u30d5\u30a1\u30a4\u30eb\u5185\u5bb9\u306eCRC-32\u304c\u683c\u7d0d\u3055\u308c\u3044\u308b\u305f\u3081\u3053\u308c\u3092\u5229\u7528\u3057\u307e\u3059\u3002\u3082\u3061\u308d\u3093\u81ea\u529b\u3067\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u306f\u306a\u304f\u3001Python\u306ezipfile.ZipFile\u30af\u30e9\u30b9\u306b\u306f\u3053\u306eCRC-32\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport zipfile\r\nimport sys\r\n\r\n# zip\u4f5c\u6210\r\nwith zipfile.ZipFile('sample.zip', 'w')as zf:\r\n    zf.write('data\/sample1.txt')\r\n\r\n# zip\u306e\u7834\u58ca\r\nwith open('sample.zip', 'rb+') as f:\r\n    f.seek(40)\r\n    f.write(0x80.to_bytes(1, byteorder=sys.byteorder))\r\n\r\n# zip\u306e\u691c\u67fb\r\nwith zipfile.ZipFile('sample.zip', 'r')as zf:\r\n    t = zf.testzip()\r\n    print(t) # data\/sample1.txt\r\n<\/pre>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u5727\u7e2e\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u30aa\u30d5\u30bb\u30c3\u30c840\u756a\u76ee\u30921\u30d0\u30a4\u30c8\u58ca\u3057\u305f\u72b6\u614b\u3067\u691c\u67fb\u3057\u3066\u3044\u307e\u3059\u3002testzip\u30e1\u30bd\u30c3\u30c9\u3067\u306f\u6700\u521d\u306b\u7834\u640d\u3092\u691c\u77e5\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u540d\u304c\u51fa\u529b\u3055\u308c\u3001\u7834\u640d\u304c\u691c\u77e5\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306fPython\u3067ZIP\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 zip\u5f62\u5f0f\u3067\u5727\u7e2e\u3059\u308b Python\u3067ZIP\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u306b\u306f\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0d\u8981\u3067\u6a19\u6e96\u306ezipfile\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u64cd\u4f5c\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd...<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[187,185,186],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/2070"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=2070"}],"version-history":[{"count":20,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/2070\/revisions"}],"predecessor-version":[{"id":2099,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/2070\/revisions\/2099"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=2070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=2070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=2070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}