Search code examples
pythonfile-formathuman-readable

User-readable file format for python list of lists


I'm considering using user-readable file format for my Python app. Right now I'm using pickle to store my data in binary. I'm not sure if XML or JSON is a way to go but basically my file contains list of lists that looks like this:

[1, 'the name of the set', [[1, 'data1', 'data2'],[2,'data3','data4']]

The list that hold the other lists containing the strings can have multiple items (even hundreds). Basically, I'd like to have something that has easy interface to convert it to/from python list and I need those integers to stay integers.


Solution

  • That's already literal JSON. JSON's probably the most popular format out there, and it's hard to argue with its legibility.

    In [105]: my_list = [1, 'the name of the set', [[1, 'data1', 'data2'],[2,'data3','data4']]]
    In [106]: my_list == json.loads(json.dumps(my_list))
    Out[106]: True