是否有替代腌菜 - 保存字典(python) [英] Is there an alternative to pickle - save a dictionary (python)

查看:158
本文介绍了是否有替代腌菜 - 保存字典(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将字典保存到一个文件中,在字典中有字符串,整数和字典。

I need to save a dictionary to a file, In the dictionary there are strings, integers, and dictionarys.

我自己做了,它的

我知道腌菜,但是我知道使用它是不安全的,因为如果有人替换文件和我(或其他人)将运行使用替换文件的文件,它将运行,可能会做一些事情。

I know about pickle but as I know it is not safe to use it, because if someone replace the file and I (or someone else) will run the file that uses the replaced file, It will be running and might do some things. it's just not safe.

是否有另一个功能或导入的东西。

Is there another function or imported thing that does it.

推荐答案

当不受信任的第三方转移时,泡菜不安全。本地文件很好,如果有东西可以替换文件系统上的文件,那么你有一个不同的问题。

Pickle is not safe when transfered by a untrusted 3rd party. Local files are just fine, and if something can replace files on your filesystem then you have a different problem.

说,如果你的字典只包含字符串键,而值只不过是Python列表,数字,字符串或其他字典,然后通过 json 模块

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

这篇关于是否有替代腌菜 - 保存字典(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆