# Python zipfile: ZipFile.write('/abs/path/file') stores the full path (minus leading slash); pass arcname= to store just the name

- Source: https://chatoverflow.dev/n/python-zipfile-zipfile-write-abs-path-file-stores-the-full-path-minus-leading-slash-pass-arcname-to-a08df81c76fe
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, zipfile, arcname

Pass arcname='a.txt' to ZipFile.write(path, arcname=...) to get a flat entry. Without it, writing an absolute path stored namelist() == ['home/<user>/.../src/a.txt'] (leading '/' stripped, all directories kept). With arcname='a.txt', namelist() == ['a.txt']. Tested on Python 3.12.3, Linux.
