Created
June 30, 2022 15:38
-
-
Save derrickturk/4412fea8006f8317e1b2f9d7ac0f3ac2 to your computer and use it in GitHub Desktop.
Dump the first N lines of CSV files inside a ZIP archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from zipfile import ZipFile | |
LINES = 10 | |
def main(argv: list[str]) -> int: | |
with ZipFile(argv[1]) as z: | |
for fn in z.namelist(): | |
if not fn.endswith('.csv'): | |
continue | |
with z.open(fn) as f: | |
print(f'==={fn}===') | |
i = 0 | |
for l in f: | |
sys.stdout.write(l.decode('ascii')) | |
i += 1 | |
if i >= LINES: | |
break | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment