Hi, I am very confused. I thought the vars were getting initialized in the __init__(self, now = time.time(), clicks = 1): part. That's why I had pass in that method. However, your suggestion fixed the problem I was having. I had to move both variables though. So now it reads: def __init__(self): self.clicks = 0 self.now = time.time() The thing that confuses me is I have written code with variables declared in the () before and they worked. Why would this time be different? Thanks Storm -- Thoughts of a Dragon: http://www.stormdragon.us/ What color dragon are you? http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/ On Sun, 2009-12-13 at 12:30 -0500, Ken Perry wrote: > > > > > You need to put self.clicks =0 in the __init__ function because you’re > trying to do this > > > > None+=1 > > > > You have to initialize it first > > > > > > If you were just setting it like > > > > Self.clicks=0 > > > > Then you could do it in the function but that would not be what you > want. So initialize it and your done. > > > > Note you don’t need __init__ if you are just doing pass > > > > > > > > > From: programmingblind-bounce@xxxxxxxxxxxxx > [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Storm > Dragon > Sent: Sunday, December 13, 2009 11:26 AM > To: programmingblind@xxxxxxxxxxxxx > Subject: Re: Strange error in Python code > > > > > > Hi, > Lol it seems so obvious now. Forgetting to put self.variable can be > detrimental. > I got all of that fixed and am still getting an error about no > attribute called now, but it is there, I double checked. Here's the > revised code: > import time > class countPresses: > def __init__(self, now = time.time(), clicks = 1): > pass > > def clickCount(self): > if time.time() <= self.now + 0.75: > self.clicks += 1 > self.now = time.time() > if self.clicks > 2: self.clicks = 1 > return self.clicks > > test = countPresses() > print str(test.clickCount()) > print str(test.clickCount()) > > > > > > -- > Thoughts of a Dragon: > http://www.stormdragon.us/ > What color dragon are you? > http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/ > > On Sun, 2009-12-13 at 07:30 -0800, R Dinger wrote: > > > > > > > Your calls to clickCount do not have parens e.g. clickCount(), > which is required for a function call. Also you have an > undefined local variable in click count named now, which is > used prior to having a value. > > > > Richard > > > ----- Original Message ----- > > From: Storm Dragon > > To: programmingblind@xxxxxxxxxxxxx > > Sent: Sunday, December 13, 2009 6:15 AM > > Subject: Strange error in Python code > > > > Hi, > I may have gone about this the wrong way. I wanted a > simple way to tell if a button has been pressed twice. > My class gives a strange error though. I wrote a > quick bit of code to test it. It just calls the > method twice in succession so it should get 1 then 2 > for output. Instead, it says: > <bound method countPresses.clickCount of > <__main__.countPresses instance at 0x7f0a97e78c68> > Here's the code: > import time > class countPresses: > def __init__(self, clicks = 1, now = time.time()): > pass > > def clickCount(self): > if now + 0.75 >= time.time(): > self.clicks += 1 > now = time.time() > if self.clicks > 2: self.clicks = 1 > return self.clicks > > test = countPresses() > print str(test.clickCount) > print str(test.clickCount) > > Thanks > Storm > > > > > > -- > Thoughts of a Dragon: > http://www.stormdragon.us/ > What color dragon are you? > > http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/ > > > > > > >