Re: Strange error in Python code

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/


       

Other related posts: