problem of types:

Larry Bates larry.bates at websafe.com
Tue Jan 17 15:57:03 CET 2006


Laurent wrote:
> I do not understand why he is talking me about 'str', no str given!!!
> 
> I have this:
> 
> ---------------------------------------------
> 
> def to_float(elt):
>   if type(elt) is list:
>     return map(to_float, elt)
>   else:
>     return float(elt)
> 
> def Denombrement(A,b,c,type):
>   .
>   .
>   .
>   A = to_float(A)
>   b = to_float(b)
>   c = to_float(c)
>   .
>   .
>   .
> 
> if __name__ == '__main__':
>   A = [[1,0],[0,1]]
>   b = [2,2]
>   c = [1,1]
>   type = 'min'
> 
>   Denombrement(A, b, c, type)
> 
> -------------------------------------------
> 
> And this error msg:
> -------------------------
> Traceback (most recent call last):
>   File "./Denombrement.py", line 160, in ?
>     Denombrement(A, b, c, type)
>   File "./Denombrement.py", line 31, in Denombrement
>     A = to_float(A)
>   File "./Denombrement.py", line 10, in to_float
>     if type(elt) is list:
> TypeError: 'str' object is not callable
> 
> ------------------------------------------
> 
> Changing 'list' to 'type(list)' don't change anything!!!!
> 

Your string variable type is masking the built-in type
function. You should avoid variables with names like
type, list, str, tuple, ... (e.g. built-ins).  As they
will mask the built-ins from your program.

-Larry Bates



More information about the Python-list mailing list