| | |
Defult (startup) Variables?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Hello again, everyone.
My program for my robot is progressing. Thanks to your help its coming along great. I've also found that I'm more and more able to solve my own problems with programming now.
One thing that I can't seem to solve:
I'm working on a part of my robot's human-socialization program in which she keeps track of the topic, and then adds her own input. For example, if I talk to my robot about Disneyland, she'll keep track of different aspects of the theme park. I do this with a variable, say for each park, and if one of the varibles is greater than 3, she'll say something like, "You seem to like Main Street a great deal." That part works more or less fine.
But when I first start up the program and mention a ride at Disneyland, such as "Rail Road" I get this exception:
<type'exceptions.AttributeError'>:'MyApp' object has no attribute 'topic' at line 1.
This is the code associated with the recognized speech "Rail Road":
I know what the exception means: it means that unless I say change the topic to "disneyland" this snippet won't work because the variable "self.topic" doesn't have anything associated with it. So what I need is a default, or startup, value for "self.topic."
As simple as it sounds, I don't know how that would work. I've tried adding code like:
under the class "MySpeechParser," which holds "self.topic"
But when I run the program, nothing seems to change. Even if I write the same code outside the MySpechParser class.
Anyone have any ideas? Thanks!
My program for my robot is progressing. Thanks to your help its coming along great. I've also found that I'm more and more able to solve my own problems with programming now.
One thing that I can't seem to solve:
I'm working on a part of my robot's human-socialization program in which she keeps track of the topic, and then adds her own input. For example, if I talk to my robot about Disneyland, she'll keep track of different aspects of the theme park. I do this with a variable, say for each park, and if one of the varibles is greater than 3, she'll say something like, "You seem to like Main Street a great deal." That part works more or less fine.
But when I first start up the program and mention a ride at Disneyland, such as "Rail Road" I get this exception:
<type'exceptions.AttributeError'>:'MyApp' object has no attribute 'topic' at line 1.
This is the code associated with the recognized speech "Rail Road":
Python Syntax (Toggle Plain Text)
if self.topic == "disneyland": speaker.Speak(random.choice(DisneyRideTrain)) else: speaker.Speak('Cool. What rail road did you ride')
I know what the exception means: it means that unless I say change the topic to "disneyland" this snippet won't work because the variable "self.topic" doesn't have anything associated with it. So what I need is a default, or startup, value for "self.topic."
As simple as it sounds, I don't know how that would work. I've tried adding code like:
Python Syntax (Toggle Plain Text)
self.topic = "nothing" print self.topic
under the class "MySpeechParser," which holds "self.topic"
But when I run the program, nothing seems to change. Even if I write the same code outside the MySpechParser class.
Anyone have any ideas? Thanks!
![]() |
Other Threads in the Python Forum
- Previous Thread: Can python do this? How?
- Next Thread: send email in python
Views: 401 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced assignment beginner bits bluetooth chmod cmd code convert count csv cursor data decimals dictionary dynamic dynamically enter examples excel external file float format frange ftp function gnu gui heads homework import input jaunty java leftmouse line linux list lists loan loop module mouse multiple newb number numbers output parsing path port prime program programming projects push py2exe pygame pygtk pyopengl pyqt python random raw_input recursion recursive scrolledtext slicenotation software ssh stderr string strings table tennis terminal text thread threading time tkinter tlapse tooltip tricks tuple tutorial ubuntu unicode update urllib urllib2 variable variables ventrilo web webservice windows wx.wizard wxpython





