This one is hopefully simple, I have a string "voltage is E=200V and the current is I=4.5A". I need to extract both float values. I have tried to use the float() function (with a sub-string of 11 to 16 in the parameters) but i get an error. I realize this probably is not good coding, I am in the beginning stages of trying to learn Python. Any help is much appreciated.
edit: Here is the code
I = 0.0
if((currentString.find('I=')) != -1):
I = float(currentString[(currentString.find('I=')):(currentString.find('A'))])
again, im new to this language and i know that looks ugly.
s = '200'; float(s)should work. – George Apr 7 '12 at 22:41E=200V, which is not a valid float. You need to be a lot more specific, you need to include code, and you need to include the error you get with a traceback. – Niklas B. Apr 7 '12 at 22:42float I = 0.0will generate a syntax error. – Joel Cornett Apr 8 '12 at 1:19