I need some help, Please!!!!!

Will Ware wware at alum.mit.edu
Sun Dec 16 21:25:47 EST 2001


The Python tutorial will be a big help.
http://www.python.org/doc/current/tut/tut.html

> I tried to create my own phone book using a dictionary to do so and I
> am having some problems. The phone book I was creating I wanted to be
> able to add someone to it, find someone in the phone book, delete
> someone, and change someone's entry.

Everything you've described here can be done with one of Python's innate
data structures, called a dictionary. Look here:
http://www.python.org/doc/current/tut/node7.html
Lo and behold, the example given is a small telephone directory. Your
professor must have been snooping around here.

> I also only wanted to use the fields Nick name, full name, phone
> number, address, and e-mail.

I'm not sure what you mean you "only" wanted use these fields. Maybe
you're figuring that Python comes with a ready-made phone book entry
data type that would include these and several others. Nope, you have
to put something together yourself.

So how to make a phone book entry data type, with these particular
fields? Go back to the tutorial, chapter 9, about classes and objects:
http://www.python.org/doc/current/tut/node11.html
You may want to design your fields as attributes of a class, and then
your phone book can be a list of instances of that class. If you want
some flexibility in how to search your phone directory, go to
http://www.python.org/doc/current/ref/customization.html
and read about "__cmp__".



More information about the Python-list mailing list