[Tutor] How can I have type "function" in my script?
Alan Gauld
alan.gauld at btinternet.com
Tue May 8 19:36:30 CEST 2012
On 08/05/12 11:23, xancorreu wrote:
> It works with
>
> c = Tag("twice", type(lambda x: x), lambda x: 2*x)
>
> but I want to specify the type of (lambda x: x) **manually** as I do
> with str in b
Unfortunately we don't always get what we want.
You have to use type for functions.
You can use a very simple function, but you need to use type()...
type(lambda : 0)
is about as simple as you can do it with lambda...
However, you still haven't said why you want the type. It's very unusual
in Python to need explicit type information. If we knew what you were
trying to do with it we might be able to offer a more pythonic way to go
about it.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list