[Tutor] need advice about a dictionary ({})

Richard D. Moores rdmoores at gmail.com
Thu Sep 8 12:58:37 CEST 2011


I've succeeded in writing a dictionary ({}) that I can use as a small
personal phone book. The dictionary (very shortened and simplified)
looks like this in the script;

p = {}

p['bp1'] = 'xxx'
p['bp2'] = 'ooo'
p['ch'] = 'zzz'
p['me'] = 'aaa'
p['mg'] = 'vvv'
p['pu1'] = 'bbb'
p['pu2'] = 'ccc'
p['pw'] = 'kkk'

I have a function that enables the user to enter 'bp', for example,
and return both 'xxx' and 'ooo'.

(The keys are initials; I've disguised the values, each of which of
course are   name, home number, mobile number, speed dial number,
etc.)

But I'd like to put the lines of the dictionary in a text file so that
I can add key/value items to it by writing to it with another script.
I think I can do that, but I need some hints about how to get  the
script to access the text file in a way that lets the user look up a
phone number. I'm thinking that the script needs to recreate the
dictionary each time it's called, but I don't know how to do that.

Thanks,

Dick Moores


More information about the Tutor mailing list