472,985 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 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 1148
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.