Adding static data files to the package
If we're going to add static data files to the package, where should we put them?
Well we can put them anywhere that's convenient within the package
folder, but it's often a good idea to create a subfolder specifically for holding the data files. This keeps data files separate from the source code and generally makes them a little easier to work with.
Note
The data files that are part of a package should be assumed to be read-only.
There are many reasons that might cause the files to not be writable at runtime. So, if we want to write data to a file while our code is running, we need to pick somewhere else to store it. Only files that do not change are appropriate for inclusion in a package:
ls example/__init__.py datals example/datadatafile.txtcat example/data/datafile.txtHello world of data
So, that said, all we have to do to include a data file in our package is drop it into our package and then access the data with the get_data
function from the util...