<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Awesome, awesome, awesome. I will check my script when I get home from work, but your explanation is top notch! I think I understand it now. Thank you.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">I will post my corrected script and the answers when I get home from work tonight.</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> </DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">Many thanks!<BR><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- Original Message ----<BR>From: Evert Rol <evert.rol@gmail.com><BR>To: Bryan Magalski <bryan_magalski@yahoo.com><BR>Cc: tutor@python.org<BR>Sent: Thursday, November 15, 2007 11:37:43 AM<BR>Subject: Re: [Tutor] Interactive Menu Woes<BR><BR>> Thank you for your suggestion. I did not create the original <BR>> script, so it will stay as is and my addition for the menu has been <BR>> adjusted.<BR>><BR>> Now that I can make a clear distinction of what I am returning, I <BR>> am getting a new error that leads me that I am trying to call a <BR>> function that cannot be seen when instantiated:<BR>><BR>> To add a name, please input he following information:<BR>> Name: Bryan<BR>> Number: 1234567890<BR>> What type of number is this? (choose one):<BR>>
1. Home:<BR>> 2. Work:<BR>> 3. Cell:<BR>> : 1<BR>> Traceback (most recent call last):<BR>> File "<A href="http://menu_modified.py/" target=_blank>menu_modified.py</A>", line 95, in <module><BR>> menu.addName()<BR>> File "<A href="http://menu_modified.py/" target=_blank>menu_modified.py</A>", line 73, in addName<BR>> enter(name, number, returnType)<BR>> AttributeError: phoneentry instance has no __call__ method<BR><BR><BR>You're first creating a phoneentry object, and then calling the <BR>actual object. That doesn't work; it's somewhat similar to:<BR>>>> a = dict()<BR>>>> a(key=5)<BR>which gives a slightly
different error, but obviously the correct <BR>form is:<BR>>>> a = dict(key=5)<BR>and also<BR>>>> phoneentry(name, number, returnType)<BR><BR>When creating an object (instantiating the class), the __init__ <BR>method is automatically called, and you provide the arguments of the <BR>__init__ method when creating the object.<BR>In your current script, the actual entry you create (enter = <BR>phoneenetry()) creates an entry with name & number 'Unknown' (default <BR>arguments), and types=UNKNOWN; then you want to assign the actual <BR>values to the entry. If you *really* want to do this (don't, though), <BR>you'd be doing:<BR>entry = phoneentry()<BR><A href="http://entry.name/" target=_blank>entry.name</A> = name<BR>entry.number = number<BR>entry.types = returnType<BR><BR>See the add() method in the phonedb class, where it is done correctly.<BR><BR><BR>A few other thoughts:<BR>- what does
numberType return if 'n is not in typeDict'? It should <BR>return UNKNOWN I guess.<BR>- why not remove that function, and put typeDict to addName? It's <BR>really only one extra line, and avoids the whole extra function call <BR>(replacing it with something one might call a 'dictionary call')<BR>- I noticed you use tabs, while the original part of the code uses <BR>spaces. Try to avoid mixing them: at some point things will go wrong <BR>(spaces are preferred; for a good read on that and other stuff: <BR><A href="http://www.python.org/doc/essays/styleguide.html" target=_blank>http://www.python.org/doc/essays/styleguide.html</A> )<BR><BR><BR> Evert<BR><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR></DIV></div><br>
<hr size=1>Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs"> Make Yahoo your homepage.</a>
</body></html>