<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Gary Herron wrote:
<blockquote cite="mid:46D6D8D2.2030102@islandtraining.com" type="cite">
<pre wrap="">luca bertini wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi,
i have strings which look like money values (ie 34.45)
is there a way to convert them into float variables?
everytime i try I get this error: "numb = float(my_line) ValueError:
empty string for float()"
"
here's the code
************
import sys
import re
for line in sys.stdin.readlines():
my_line = line.rstrip()
numb = float(my_line)
print numb
</pre>
</blockquote>
<pre wrap=""><!---->The clue "empty string for float" must mean that the value of my_line is
an empty string. And that would seem to mean you have an empty line in
your input.
So... Either remove the empty lines, or test my_line before calling
float on it.
Gary Herron
</pre>
</blockquote>
Or let the exception get raised, and handle it.<br>
<br>
</body>
</html>