使用 sqlite3 并使用名称
http://docs.python.org/library/sqlite3.html存储用户数据
import sqlite3
db = sqlite3.connect("settings.db")
c = db.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS userdata (
user_name TEXT,
settings1 TEXT,
settings2 TEXT
);""")
c.execute("INSERT INTO user_data (user_name,settings1,settings2) VALUES (?,?,?)",("bob","some_Value","some Other Value")
db.commit() #save it
c.execute("SELECT * FROM userdata WHERE user_name=?",GetUserName())
print c.fetchall()
或使用泡菜http://docs.python.org/library/pickle.html
import pickle
try:
with open("settings.dat") as f:
print pickle.load(f)
except IOError:
print "No Settings Found"
user_data = {"bob":{"path1":"some/path","otherVar":"56"},
"paul":{"url":"http://docs.python.org/library/sqlite3.html"}
}
with open("settings.dat","wb") as f:
pickle.dump(f)
这两个都没有经过我的测试......它们只是在我的脑海中,可能包含小错误