I do not understand your format:
>>> AB={'Joshua' : 'Joshua: ''Email: sho0uk0m0o@gmail.com Phone: (802) 3-5-2206',
'Ashley' : 'Ashley: ''Email: a000@gmail.com Phone: (802) 820-0000',}
>>> AB
{'Joshua': 'Joshua: Email: sho0uk0m0o@gmail.com Phone: (802) 3-5-2206', 'Ashley': 'Ashley: Email: a000@gmail.com Phone: (802) 820-0000'}
>>>
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
For storing a few values, like phone number and e-mail address, you can use a list which is easier to understand and use.
AB={'Joshua' : ['sho0uk0m0o@gmail.com', '(802) 3-5-2206'],
'Ashley': ['a000@gmail.com', '(802) 820-0000']}
print "%s, e-mail=%s, phone=%s" % ("Joshua", AB["Joshua"][0], AB["Joshua"][1])
new_name = "Bill"
new_email= "bill@domain.com"
new_phone= "(802) 123-4567"
AB[new_name] = [new_phone, new_email]
print AB
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
If you are ready to use python 2, you can write it very easily using a class I wrote in this code snippet http://www.daniweb.com/software-development/python/code/258640 .
Here is a possible code
from optcmd import OptCmd
AB = dict()
class AddressBookCmd(OptCmd):
def emtpyline(self):
pass
def do_add(self, name, email, phone):
"""
usage: add name email phone
Add an entry in the address book.
"""
AB[name] = [email, phone]
def do_get(self, name):
"""
usage: get name
Retrieve the address book's entry for name.
"""
if name in AB:
print("{n}\n\temail: {e}\n\tphone: {p}".format(
n = name, e = AB[name][0], p = AB[name][1]))
else:
print("No such name in the address book.")
if __name__ == "__main__":
cmd = AddressBookCmd()
cmd.prompt = "[AB] "
cmd.cmdloop("Welcome to the Address Book".center(72))
""" Example session
Welcome to the Address Book
[AB] add Joshua sho0uk0m0o@gmail.com "(802) 3-5-2206"
[AB] add Ashley a000@gmail.com "(802) 820-0000"
[AB] get Joshua
Joshua
email: sho0uk0m0o@gmail.com
phone: (802) 3-5-2206
[AB] get Woooee
No such name in the address book.
[AB] help get
usage: get name
Retrieve the address book's entry for name.
[AB] quit
"""
I couldn't find the time to translate optcmd into python 3 until now ...
Gribouillis
Posting Maven
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691