problem of types:

L

Laurent

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
 
F

Fredrik Lundh

Laurent said:
I do not understand why he is talking me about 'str', no str given!!!

I have this:

this uses type
if __name__ == '__main__':
A = [[1,0],[0,1]]
b = [2,2]
c = [1,1]
type = 'min'

and this sets type to a string.
if type(elt) is list:
TypeError: 'str' object is not callable

Changing 'list' to 'type(list)' don't change anything!!!!

that's because the error says that you're trying to call a string,
which is exactly what happens here.

</F>
 
L

Larry Bates

Laurent said:
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,276
Messages
2,571,384
Members
48,073
Latest member
ImogenePal

Latest Threads

Top