在Python中存储简单的用户设置 [英] Store simple user settings in Python
问题描述
我编程的网站,用户将有一些设置,如他们选择的配色方案等。我很高兴将这些存储为纯文本文件,安全不是一个问题。
I am programming a website in which users will have a number of settings, such as their choice of colour scheme, etc. I'm happy to store these as plain text files, and security is not an issue.
我目前看到的方式是:有一个字典,其中所有的键都是用户,值是字典与用户的设置。
The way I currently see it is: there is a dictionary, where all the keys are users and the values are dictionaries with the users' settings in them.
例如,userdb [bob] [colour_scheme]的值为blue。
For example, userdb["bob"]["colour_scheme"] would have the value "blue".
方式将其存储在文件?腌制字典?
What is the best way to store it on file? Pickling the dictionary?
有没有更好的方法来做我想做的事?
Are there better ways of doing what I am trying to do?
推荐答案
使用 cPickle 字典将是我的选择。字典是一种自然适合这些类型的数据,所以根据您的要求,我没有理由不使用它们。那,除非你正在考虑从非Python应用程序中读取它们,在这种情况下,你必须使用语言中性的文本格式。即使在这里,你可以用腌汁加出口工具。
Using cPickle on the dictionary would be my choice. Dictionaries are a natural fit for these kind of data, so given your requirements I see no reason not to use them. That, unless you are thinking about reading them from non-python applications, in which case you'd have to use a language neutral text format. And even here you could get away with the pickle plus an export tool.
这篇关于在Python中存储简单的用户设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!