Is there an alternative to pickle - save dictionary (python)

I need to save the dictionary to a file, the dictionary has strings, integers and dictionaries.

I did it on my own, and not beautiful and pleasant for the user.

I know about the brine, but since I know that it is unsafe to use it, because if someone replaces the file, and I (or someone else) starts the file that uses the replaced file, it will be launched and can do some things . it is simply not safe.

Is there any other function or imported thing that does this.

+4
source share
3 answers

Dispersion is not safe when transferring to unreliable third parties. Local files are just fine, and if something can replace files on your file system, then you have another problem.

However, if your dictionary contains nothing but string keys, and values ​​are nothing but lists, numbers, strings, or other Python dictionaries, then use JSON via json .

+5
source

Assuming your dictionary contains only basic data types, the normal json answer is a popular, well-defined language for this kind of thing.

If your dictionary contains more complex data, you will have to manually serialize it, at least in part.

0
source

JSON is not exactly a Python path due to several reasons:

  • It cannot wrap / unpack all Python data types: there is no support for sets or tuples.
  • Not fast enough, because he needs to deal with text data and encodings.

Try sPickle instead.

0
source

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


All Articles