I'm kinda new to python and i attended a tutorial the other day on basic/advanced methods in python. I went back to my appt. and decided to make a phone book.
This project consists of 2 files : 1) the phonebook (organized by county) and 2) the code for find().
CODE
def find():
a = raw_input("What county do they live in?")
b = raw_input("What is their First Name?")
if a.has_key(b):
print a[b]
else:
print "No Such Name."
But when i run the code i get this error:
CODE
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
find()
File "G:\Python25\Find2.py", line 5, in find
if a.has_key(b):
AttributeError: 'str' object has no attribute 'has_key'
I am wondering if there is a way to cast a string object as a dictionary so that i can look up the name and return the phone number. Thank you