Armando Serrano Lombillo a écrit :
> Why does Python give an error when I try to do this:
> 
>>>> len(object=[1,2])
> Traceback (most recent call last):
>   File "<pyshell#40>", line 1, in <module>
>     len(object=[1,2])
> TypeError: len() takes no keyword arguments
> 
> but not when I use a "normal" function:
> 
>>>> def my_len(object):
>       return len(object)
> 
>>>> my_len(object=[1,2])
> 2

In the second case, the name of the argument *is* 'object'. Which is not 
the case for the builtin len (which, fwiw, has type 
'builtin_function_or_method', not 'function', so inspect.getargspec 
couldn't tell me more).

<ot>
While we're at it, you should avoid using builtin's names for 
identifiers - here, using 'object' as the arg name shadows the builtin 
'object' class).
</ot>

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to