[Tutor] How can I have type "function" in my script?
xancorreu
xancorreu at gmail.com
Tue May 8 20:31:41 CEST 2012
Al 08/05/12 19:36, En/na Alan Gauld ha escrit:
> 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...
A much pain for me. I think there should be a type.function avaliable in
python, like str, int, etc. exists. I think as python is O-O language
and have (or at least the page says that) higher-order function, I
should could type:
isinstance(2, function)
like I do
isinstance(2, int)
Do you understand my reasoning?
>
> 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.
>
>
Yes, I know that the pythonic way is to not define types in variables.
The variables are free while there is no assign to these. I need type
because I want to implement Tag as triple of name, type and value. I
want to differentiate between a tag with type str and value "today" and
a tag with tag with type data and value "today".
That's all.
Thanks for the answer.
Xan.
More information about the Tutor
mailing list