473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

what wrong when I defined my class

Expand|Select|Wrap|Line Numbers
  1. class Test:
  2.     def __init__(self):
  3.         self._power = False
  4.         self._v = 5
  5.         self._station = 80.0
  6.         self._presets= [ 72.0, 74.4, 76.6]
  7.  
  8.     def togglePower(self):  # when I tried it this did not work
  9.         self._powerOn = not self._PowerOn
  10.  
  11.     def setPreset(self, ind): 
  12.             self._presets[ind]=self_station #when I enter .setPreset(1), it did not work either, global name '_station' is not defined
  13.  
  14.  
Oct 8 '07 #1
5 1155
elcron
43
Expand|Select|Wrap|Line Numbers
  1. class Test:
  2.     def __init__(self):
  3.         self._power = False
  4.         self._v = 5
  5.         self._station = 80.0
  6.         self._presets= [ 72.0, 74.4, 76.6]
  7.  
  8.     def togglePower(self):  # when I tried it this did not work
  9.         self._powerOn = not self._PowerOn
  10.  
  11.     def setPreset(self, ind): 
  12.             self._presets[ind]=self_station #when I enter .setPreset(1), it did not work either, global name '_station' is not defined
  13.  
  14.  
Expand|Select|Wrap|Line Numbers
  1. class Test:
  2.     def __init__(self):
  3.         self._power = False
  4.         self._v = 5
  5.         self._station = 80.0
  6.         self._presets= [ 72.0, 74.4, 76.6]
  7.  
  8.     def togglePower(self):  # when I tried it this did not work
  9.         self._powerOn = not self._PowerOn
  10.  
  11.     def setPreset(self, ind): 
  12.             self._presets[ind]=self._station
  13.  
  14.  
you left out the "." after self and before _station.
Oct 8 '07 #2
Expand|Select|Wrap|Line Numbers
  1. class Test:
  2.     def __init__(self):
  3.         self._power = False
  4.         self._v = 5
  5.         self._station = 80.0
  6.         self._presets= [ 72.0, 74.4, 76.6]
  7.  
  8.     def togglePower(self):  
  9.         self._powerOn = not self._powerOn
  10.  
  11.  
Thank you very much.

Another question, how can it make the following code return "True"
Expand|Select|Wrap|Line Numbers
  1.     def togglePower(self):  
  2.         self._powerOn = not self._powerOn
  3.  
It only return "none" when I try
Expand|Select|Wrap|Line Numbers
  1. print a.togglePower()
  2.  
Oct 8 '07 #3
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. class Test:
  2.     def __init__(self):
  3.         self._power = False
  4.         self._v = 5
  5.         self._station = 80.0
  6.         self._presets= [ 72.0, 74.4, 76.6]
  7.  
  8.     def togglePower(self):  
  9.         self._powerOn = not self._powerOn
  10.  
  11.  
Thank you very much.

Another question, how can it make the following code return "True"
Expand|Select|Wrap|Line Numbers
  1.     def togglePower(self):  
  2.         self._powerOn = not self._powerOn
  3.  
It only return "none" when I try
Expand|Select|Wrap|Line Numbers
  1. print a.togglePower()
  2.  
Expand|Select|Wrap|Line Numbers
  1.     def togglePower(self):  
  2.         self._power = not self._power
  3.         return self._power
  4. print a.togglePower()
  5.  
Oct 8 '07 #4
Thank you.


Another question related to the one below, can anyone locate the error in the source code below?
Expand|Select|Wrap|Line Numbers
  1. class Test:
  2.     def __init__(self):
  3.         self._powerOn = False
  4.         self._v = 10
  5.         self._station = 10
  6.         self._presets= [ 5, 6, 7, 8]
  7.  
  8.     def togglePower(self):
  9.         self._powerOn = not self._powerOn
  10.  
  11.     def setP(self, i):
  12.             self._presets[i]=self._station
  13.  
  14.     def gotoP(self, i):
  15.         self._station = self._presets[i]
  16.  
  17.     def increaseV(self):   
  18.         self._v = self._v +2
  19.  
  20.     def decreaseV(self):   
  21.         self._v = self._v -2
  22.  
  23.     def increaseStation(self):   
  24.         self._station = self._station + 1
  25.  
  26.     def decreaseStation(self):   
  27.         self._station = self._station - 1
  28.  
Oct 8 '07 #5
bartonc
6,596 Expert 4TB
Thank you.


Another question related to the one below, can anyone locate the error in the source code below?
Expand|Select|Wrap|Line Numbers
  1. class Test:
  2.     def __init__(self):
  3.         self._powerOn = False
  4.         self._v = 10
  5.         self._station = 10
  6.         self._presets= [ 5, 6, 7, 8]
  7.  
  8.     def togglePower(self):
  9.         self._powerOn = not self._powerOn
  10.  
  11.     def setP(self, i):
  12.             self._presets[i]=self._station
  13.  
  14.     def gotoP(self, i):
  15.         self._station = self._presets[i]
  16.  
  17.     def increaseV(self):   
  18.         self._v = self._v +2
  19.  
  20.     def decreaseV(self):   
  21.         self._v = self._v -2
  22.  
  23.     def increaseStation(self):   
  24.         self._station = self._station + 1
  25.  
  26.     def decreaseStation(self):   
  27.         self._station = self._station - 1
  28.  
It will be hard for us to tell without an example of which error you are getting. I do see that
Expand|Select|Wrap|Line Numbers
  1. # these two
  2.  
  3.     def setP(self, i):
  4.             self._presets[i]=self._station
  5.  
  6.     def gotoP(self, i):
  7.         self._station = self._presets[i]
will raise an error if you call the funtion with a number greater that 3.
Oct 8 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
11
by: Micha | last post by:
Hello there, I think I've run into some classic c++ pitfall and maybe some of you guys can help me out. For my project I will need to use matrices and vectors and so I decided to implement them...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
8
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
2
by: Ltez | last post by:
I use Python 2.4.4. Please read the code below: ----------------------------------------------------------- from new import classobj def mymeta(name,bases,clsdict): print 'meta: %s'%name...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
5
by: Vols | last post by:
class A{ public: int x; }; class B : public A{ public: int y; }; void foo()
167
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.