[Tutor] How can I have type "function" in my script?

xancorreu xancorreu at gmail.com
Mon May 7 20:24:56 CEST 2012


I have this script:

from types import *

class Tag:

     def __init__(self, nom, tipus, valor):
         self.nom = nom
         self.tipus = tipus
         self.valor = valor

     def __str__(self):
         return "Nom: " + str(self.nom) + ", Tipus: " + str(self.tipus)  
+ ", Valor: " + str(self.valor)

def main():
     a = Tag("descripció", str, "primera tasca")
     b = Tag("unmes", str, lambda x: x+1)

if __name__ == '__main__':

All is ok, but when I substitute b = Tag("unmes", str, lambda x: x+1) 
for b = Tag("unmes", function, lambda x: x+1) I receive an error that 
function is not globally defined variable. How can I say that function 
is the types.function? (the type of lambda x: x+1)

I use python3

Thanks in advance,

More information about the Tutor mailing list