Preferred python data storage / retrieval method

I would like to include data files with the Python package. It is best to put them in the actual package as suggested here , i.e.

setup.py
src/
    mypkg/
        __init__.py
        module.py
        data/
            tables.dat
            spoons.dat
            forks.dat

or is there a better way to do this? What is the best way to get a data file from inside python? Should i use

mypkg.__path__ + 'data/tables.dat'

for example, or should I use

pkgutil.getdata('mypkg','tables.dat')

or again, is there any other better way to do this?

Generally speaking, what is the current preferred way of processing data inside Python packages?

+3
source share
2 answers

pkgutil , , ZIP , , . , , .:)

+3

Python Pickle. , (), , script.

, , , :

from package import data
-2

Source: https://habr.com/ru/post/1729802/


All Articles