Skip to content

Instantly share code, notes, and snippets.

@derrickturk
Created June 30, 2022 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derrickturk/4412fea8006f8317e1b2f9d7ac0f3ac2 to your computer and use it in GitHub Desktop.
Save derrickturk/4412fea8006f8317e1b2f9d7ac0f3ac2 to your computer and use it in GitHub Desktop.
Dump the first N lines of CSV files inside a ZIP archive
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