Question: This is my code. I want to read the data from "data.txt" and convert it to type `float`, but there is a problem converting the data. The error says " could not convert string to float: ".

```
def CrearMatriz():
    archi = open("data.txt", "r")
    num = archi.readlines() 
    for lines in num:
        nums= [float(x) for x in lines.strip().split(",")]
    return nums
Numero = CrearMatriz()

```

The file contains numbers separated by commas.

Answer: 
I am not saying it's the perfect answer, but I suggest you do your parsing outside of the list comprehension proper and append to nums on success, at least until your formatting fixes everything.

From looking at the errors I am getting, one possibility is that it looks like lines.strip() doesn't account for blank lines in your file.

```
def CrearMatriz():
    archi = open("data.txt", "r")
    num = archi.readlines() 
    for lines in num:
        nums= [float(x) for x in lines.strip().split(",")]
    return nums

def CrearMatriz2():
    with open("data.txt", "r") as archi:
        #having it in a separate function allows more robust formatting
        #and error handling.  append to nums on success
        def tofloat(nums, x, lines, cntr):
            try:
                res = float(x)
                assert isinstance(res, float)
                nums.append(float(x))
            except Exception, e:
                msg = "exception %s on field:%s: for line #%s:%s:" % (e, x, cntr,lines)
                print (msg)
                return

        nums = []
        num = archi.readlines() 
        for cntr, lines in enumerate(num):
            [tofloat(nums, x, lines, cntr) for x in lines.strip().split(",")]
        return nums

data="""
0.12,30.2,30.5,22
3,abc,4

"""

with open("data.txt","w") as f_test:
    f_test.write(data)

try:
    print "\n\ncalling CrearMatriz"
    Numero = CrearMatriz()
    print "\nCrearMatriz()=>", Numero
except Exception, e:
    print e

try:
    print "\n\ncalling CrearMatriz2"
    Numero = CrearMatriz2()
    print "\nCrearMatriz2()=>", Numero
except Exception, e:
    print e

```

and this gives...

```
calling CrearMatriz
could not convert string to float:

calling CrearMatriz2
exception could not convert string to float:  on field:: for line #0:
:
exception could not convert string to float: abc on field:abc: for line #2:3,abc,4
:
exception could not convert string to float:  on field:: for line #3:
:

CrearMatriz2()=> [0.12, 30.2, 30.5, 22.0, 3.0, 4.0]

```
I'm interested in the type of 

```
lines.strip().split(",")

```

It seems to me that strip() should work on a string, but lines would be a list of strings. You might need a double comprehension, something like:

```
[[float(x) for x in line.strip().split(",")] for line in lines]

```

Without your data, I can't verify this, though.

You might try removing the float(x) and just using

```
nums= [x for x in lines.strip().split(",")]
print(nums)

```

to see what the exact values are that float(x) is choking on.