Python - How do I make a dictionary inside of a text file? -


i'm writing program allows user create username , password. how write dictionary text file, , retrieve when need it? also, if there easier way i'm welcome new ideas.

use python serialization mechanism - pickle.

small example:

>>> import pickle >>> s = pickle.dumps({'username': 'admin', 'password': '123'}) >>> s "(dp0\ns'username'\np1\ns'admin'\np2\nss'password'\np3\ns'123'\np4\ns." 

now can save content of s file. after can read , decode:

>>> pickle.loads(s) {'username': 'admin', 'password': '123'} 

but approach not quite safe. don't use dangerous data or data rely on.

check out "why python pickle insecure" nadia alramli.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -