[Tutor] Interactive Menu Woes
Bryan Magalski
bryan_magalski at yahoo.com
Wed Nov 14 12:06:16 CET 2007
Greetings all!!
This is my first post and I am going to probably be vague at first, but, I will try my best to be specific. I am a very GREEN scripter/programmer, so please be as descriptive as possible. Ok, enough excuses, on with my question!
Here is my issue:
I am trying to build a menu for the following script to make it more "user friendly". Nothing fancy, just a simple add data and look up the entered results.
The problem is that when I run my modified version with this snippet (please see attachment for original and my modified versions):
[code]
class MenuInput:
# ask user to input data and store to be passed to manageable variables.
def addName(self):
print "To add a name, please input he following information: "
self.enter = phoneentry()
self.name = raw_input("Name: ")
self.number = raw_input("Number: ")
self.get = int(raw_input("What type of number is this? (choose one): \n 1. Home:\n 2. Work:\n 3. Cell:\n : "))
def numberType(self, get = 1):
if self.get == 1:
self.returnType = HOME
#return self.getType
elif self.gete == 2:
self.returnType = WORK
#return self.getType
elif self.get == 3:
self.returnType = FAX
#return self.getType
return self.returnType
self.type = numberType(self.get)
self.enter(self.name, self.number, self.returnType)
def display(self):
print "Enter a name to look up: (leave blank to exit)"
self.Name = str(raw_input("Name: "))
print "%s has the following information: " % self.Name
if self.Name != "":
foo = phonedb()
for entry in foo.lookup(self.Name):
print '%-40s %s (%s)' % (entry.name, entry.number, entry.showtype())
print
[/code]
when I instantiate and run it with:
[code]
menu = MenuInput()
menu.addName()
[/code]
and enter the information asked, I am given this runtime error:
[error]
To add a name, please input he following information:
Name: Bryan
Number: 1234567
What type of number is this? (choose one):
1. Home:
2. Work:
3. Cell:
: 1
Traceback (most recent call last):
File "examples\testpy\my_object_modified.py", line 101, in <module>
menu.addName()
File "examples\testpy\my_object_modified.py", line 85, in addName
self.type = numberType(self.get)
File "examples\testpy\my_object_modified.py", line 74, in numberType
if self.get == 1:
AttributeError: 'int' object has no attribute 'get'
>>>
[/error]
I "think" that this has something to do with passing the results or possibly my functions are not properly calling (proper terminology?) each other.
Now what/where am I wrong? As this is part of an object oriented programming class, I wanted the menu constructed inherent to the class.
Thank you in advance. --Bryan
____________________________________________________________________________________
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071114/843617eb/attachment.htm
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: modified.py
Url: http://mail.python.org/pipermail/tutor/attachments/20071114/843617eb/attachment.txt
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: original.py
Url: http://mail.python.org/pipermail/tutor/attachments/20071114/843617eb/attachment-0001.txt
More information about the Tutor
mailing list