> Thank you for your suggestion.  I did not create the original  
> script, so it will stay as is and my addition for the menu has been  
> adjusted.
>
> Now that I can make a clear distinction of what I am returning, I  
> am getting a new error that leads me that I am trying to call a  
> function that cannot be seen when instantiated:
>
> To add a name, please input he following information:
> Name: Bryan
> Number: 1234567890
> What type of number is this? (choose one):
>                      1. Home:
>                      2. Work:
>                      3. Cell:
>                      : 1
> Traceback (most recent call last):
>   File "menu_modified.py", line 95, in <module>
>     menu.addName()
>   File "menu_modified.py", line 73, in addName
>     enter(name, number, returnType)
> AttributeError: phoneentry instance has no __call__ method


You're first creating a phoneentry object, and then calling the  
actual object. That doesn't work; it's somewhat similar to:
 >>> a = dict()
 >>> a(key=5)
which gives a slightly different error, but obviously the correct  
form is:
 >>> a = dict(key=5)
and also
 >>> phoneentry(name, number, returnType)

When creating an object (instantiating the class), the __init__  
method is automatically called, and you provide the arguments of the  
__init__ method when creating the object.
In your current script, the actual entry you create (enter =  
phoneenetry()) creates an entry with name & number 'Unknown' (default  
arguments), and types=UNKNOWN; then you want to assign the actual  
values to the entry. If you *really* want to do this (don't, though),  
you'd be doing:
entry = phoneentry()
entry.name = name
entry.number = number
entry.types = returnType

See the add() method in the phonedb class, where it is done correctly.


A few other thoughts:
- what does numberType return if 'n is not in typeDict'? It should  
return UNKNOWN I guess.
- why not remove that function, and put typeDict to addName? It's  
really only one extra line, and avoids the whole extra function call  
(replacing it with something one might call a 'dictionary call')
- I noticed you use tabs, while the original part of the code uses  
spaces. Try to avoid mixing them: at some point things will go wrong  
(spaces are preferred; for a good read on that and other stuff:  
http://www.python.org/doc/essays/styleguide.html )


   Evert

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to