file access

Ruediger Maehl ruediger.maehl at dzsh.de
Tue Feb 20 14:32:02 CET 2001


Ben de Luca schrieb in Nachricht
<3a8e53e2$0$25475$7f31c96c at news01.syd.optusnet.com.au>...
>when i write the data to a file whats the best way? I guess there is no way
>to sumb the dictonaries strait to disk? i will have to parse it?
>
You can write it to disk like:

# build a dictionary
a = {}
a["AAA"] = 1
a["BBB"] = 2
a["CCC"] = 3

# writing out
f = open("dict.tmp", "w")
f.write(repr(a))
f.close()

# reading in
f = open("dict.tmp", "r")
b = eval(f.read())
f.close()
print type(b), b


HTH
Rüdiger





More information about the Python-list mailing list