Help with python

Hi, quiet new to python, starting to get it but have some problems:

ok, so i want “normal” to get+1 everytime i press the button “W” is this how I do it?

add = 1
base.accept( "w" , self.__setattr__,["normal"+"add"])

And also, kinda basic, but how to i call and loop a function i python?

if you put something into “” it is a string.
if you do “normal”+“add” you get “normaladd”.

base.accept( "w" , self.__setattr__,["normal"+"add"])

is equal to

base.accept( "w" , self.__setattr__,["normaladd"]) 

what you could do:

add = 1
normal = 0
def addToNormal( num ):
  normal += num
base.accept( "w", addToNormal, [add] )

I’d recommend to avoid using setattr until you really know what it’s for. Better have a bit more code, but understand what you do in there.

# Usually a function is called using it's name
# because we call a function (base.accept) which will later handle the function call for us we give the function as parameter and the functions parameters in a list [add]
base.accept( "w", addToNormal, [add] )

A better and cleaner solution is using lambdas:

add = 1
normal = 0
base.accept( "w", lambda: normal += add )

pro, there is some thing wrong with your lambda… they cant contain “=”

>>> f = lambda: normal += add
  File "<stdin>", line 1
    f = lambda: normal += add
SyntaxError: invalid syntax

Hmm, I could have sworn I tried that. Thanks for pointing it out, though.