Package data

A package might contain more than just Python source files. Sometimes, you might need to include other types of files as well. For example, a package may include one or more image files, a large text file containing a list of all the ZIP codes in the USA, or any other type of data you may need. If you can store something in a file, you can include this file as part of your Python package.

Normally, you would place your package data in a separate sub-directory within the package directory. To access these files, your package needs to know where to find this sub-directory. While you could hardwire the location of this directory into your package, this won't work if your package is to be reused or moved. It's also not necessary as you ...

Get Modular Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.