如何获取内存中 Python 字典的 Python 源代码 表示?
我决定在阅读 Thomas Kluyver 的 comment 后问这个问题在 Rob Galanakis 的博客文章中,标题为 Why bother with python and config files?托马斯在他的评论中说
But if you want any way to change settings inside the application (like a preferences dialog), there’s no good way to automatically write a correct Python file.
最佳答案
假设它只使用“基本”Python 类型,你可以写出结构的repr()
,然后使用ast.literal_eval()
读取它之后回来。
关于python - 如何将 Python 内存字典作为 Python 源代码保存到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11594304/