Xan, it's "not defined" because you haven't defined a function called "function" or any variable called "function".<div><div><br></div><div><div>Nom: descripci, Tipus: <type 'str'>, Valor: primera tasca</div>
<div>Nom: unmes, Tipus: <type 'str'>, Valor: <function <lambda> at 0x10df736e0></div><div><div><div><br></div><div>str comes back as <type 'str'> because str is a built-in method and python and will always be in the namespace.</div>
<div><br></div><div>See <a href="http://docs.python.org/library/functions.html#str">http://docs.python.org/library/functions.html#str</a><br><br><div class="gmail_quote">On Mon, May 7, 2012 at 1:24 PM, xancorreu <span dir="ltr"><<a href="mailto:xancorreu@gmail.com" target="_blank">xancorreu@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I have this script:<br>
<br>
from types import *<br>
<br>
class Tag:<br>
<br>
def __init__(self, nom, tipus, valor):<br>
self.nom = nom<br>
self.tipus = tipus<br>
self.valor = valor<br>
<br>
def __str__(self):<br>
return "Nom: " + str(self.nom) + ", Tipus: " + str(self.tipus) + ", Valor: " + str(self.valor)<br>
<br>
<br>
def main():<br>
a = Tag("descripció", str, "primera tasca")<br>
b = Tag("unmes", str, lambda x: x+1)<br>
print(a)<br>
print(b)<br>
<br>
if __name__ == '__main__':<br>
main()<br>
<br>
<br>
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)<br>
<br>
I use python3<br>
<br>
<br>
Thanks in advance,<br>
Xan.<br>
______________________________<u></u>_________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/tutor</a><br>
</blockquote></div><br></div>
</div></div></div></div>