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

Glen Zangirolami glenbot at gmail.com
Mon May 7 21:01:54 CEST 2012


Xan, it's "not defined" because you haven't defined a function called
"function" or any variable called "function".

Nom: descripci, Tipus: <type 'str'>, Valor: primera tasca
Nom: unmes, Tipus: <type 'str'>, Valor: <function <lambda> at 0x10df736e0>

str comes back as <type 'str'> because str is a built-in method and python
and will always be in the namespace.

See http://docs.python.org/library/functions.html#str

On Mon, May 7, 2012 at 1:24 PM, xancorreu <xancorreu at gmail.com> wrote:

> Hi,
>
> 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)
>    print(a)
>    print(b)
>
> if __name__ == '__main__':
>        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,
> Xan.
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120507/027386ec/attachment.html>


More information about the Tutor mailing list