ch08
This commit is contained in:
@@ -0,0 +1 @@
|
||||
This is content1.txt
|
||||
@@ -0,0 +1 @@
|
||||
This is content2.txt
|
||||
@@ -0,0 +1 @@
|
||||
This is subfolder/content3.txt
|
||||
@@ -0,0 +1 @@
|
||||
This is subfolder/content4.txt
|
||||
@@ -0,0 +1,11 @@
|
||||
# files/compression/tar.py
|
||||
import tarfile
|
||||
|
||||
with tarfile.open('example.tar.gz', 'w:gz') as tar:
|
||||
tar.add('content1.txt')
|
||||
tar.add('content2.txt')
|
||||
tar.add('subfolder/content3.txt')
|
||||
tar.add('subfolder/content4.txt')
|
||||
|
||||
with tarfile.open('example.tar.gz', 'r:gz') as tar:
|
||||
tar.extractall('extract_tar')
|
||||
@@ -0,0 +1,14 @@
|
||||
# files/compression/zip.py
|
||||
from zipfile import ZipFile
|
||||
|
||||
|
||||
with ZipFile('example.zip', 'w') as zp:
|
||||
zp.write('content1.txt')
|
||||
zp.write('content2.txt')
|
||||
zp.write('subfolder/content3.txt')
|
||||
zp.write('subfolder/content4.txt')
|
||||
|
||||
|
||||
with ZipFile('example.zip') as zp:
|
||||
zp.extract('content1.txt', 'extract_zip')
|
||||
zp.extract('subfolder/content3.txt', 'extract_zip')
|
||||
Reference in New Issue
Block a user