[Python] How to store structured data in a python package?

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I'm currently developing a python package which among other things generates maps for a very low resolution driving game.

    The maps are generated by combining predefined tiles. Those tiles have to be stored somehow. Each tile is a 9x9 array of sets containing zero to three strings. There are about 30 of those tiles.

    Currently I store the tiles as constants in a python file and simply import them when I have to use them. I don't think it is affecting the performance (the file is only 89 KB big).

    However, this dosn't feel very elegant. While the data is technically human readable, the file is to big to usefully look at (~3000 lines) or edit.

    I could transfer the data to json files, but that would not make it any more readable and add an extra decode step when using it. I don't want to use pickle because changes to pickled files can't be usefully tracked by git.

    The ideal solution would be both plain text (so that changes can usefully be tracked by git) and not complicated when publishing the package (I heard that a extra setup step is necessary when accessing non-python files in a package?).

    Continue reading...

Compartilhe esta Página