PyDocs

Nav

Data Compression and Archiving

PyZipFile.writepy

  • PyZipFile.writepy(pathname, basename='', filterfunc=None)
Add all files from "pathname" to the ZIP archive.

If pathname is a package directory, search the directory and
all package subdirectories recursively for all *.py and enter
the modules into the archive.  If pathname is a plain
directory, listdir *.py and enter all modules.  Else, pathname
must be a Python *.py file and the module will be put into the
archive.  Added modules are always module.pyc.
This method will compile the module.py into module.pyc if
necessary.
If filterfunc(pathname) is given, it is called with every argument.
When it is False, the file or directory is skipped.
Changed in 3.4, 3.6.2, 3.7
  • 3.4: Added the filterfunc parameter.
  • 3.6.2: The pathname parameter accepts a path-like object.
  • 3.7: Recursion sorts directory entries.
1 Example
>>> zf = PyZipFile('myprog.zip')
>>> def notests(s):
...     fn = os.path.basename(s)
...     return (not (fn == 'test' or fn.startswith('test_')))
...
>>> zf.writepy('myprog', filterfunc=notests)
from the Python docs
See Also
No see-alsos for zipfile/PyZipFile.writepy
0 Notes
No notes for PyZipFile.writepy