I am trying to get abs
of float
, which is initially stored in str
as:
for q in range(0, len(moms), 1):
print("mom types", type(moms[q]))
out.write(abs(float(moms[q]))+" ")
out.write("\n")
which gives error:
mom types <class 'str'>
Traceback (most recent call last):
File "s2gen.py", line 192, in <module>
out.write(abs(float(moms[q]))+" ")
TypeError: unsupported operand type(s) for +: 'float' and 'str'
I am not regular in python, but it seems, the string to float is correct, as from here or here. Not sure, what is going wrong here.