mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-27 22:11:13 +00:00
Update conc_gzip_files.py
This commit is contained in:
parent
98980fc77b
commit
8c3461624f
|
@ -14,15 +14,15 @@ def conc_gzip_files(in_dir, out_file, append=False):
|
||||||
else creates a new output file.
|
else creates a new output file.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
write_mode = 'w'
|
write_mode = 'bw'
|
||||||
if append:
|
if append:
|
||||||
write_mode = 'a'
|
write_mode = 'ba'
|
||||||
gzips = [os.path.join(in_dir, i) for i in os.listdir(in_dir) if i.endswith('.gz')]
|
gzips = [os.path.join(in_dir, i) for i in os.listdir(in_dir) if i.endswith('.gz')]
|
||||||
with open(out_file, write_mode) as ofile:
|
with open(out_file, write_mode) as ofile:
|
||||||
for f in gzips:
|
for f in gzips:
|
||||||
with gzip.open(f, 'rb') as gzipf:
|
with gzip.open(f, 'rb') as gzipf:
|
||||||
for line in gzipf:
|
for line in gzipf:
|
||||||
ofile.write(line.decode())
|
ofile.write(line)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
conc_gzip_files('/home/usr/my_dir', '/home/usr/test.txt')
|
conc_gzip_files('/home/usr/my_dir', '/home/usr/test.txt')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user