builtins.ValueError: could not convert string to float:的问题

import turtle

def main():
    turtle.title('数据驱动的动态绘制路径')
    turtle.setup(800, 600, 0, 0)
    pen = turtle.Turtle()
    pen.width(5)
    pen.shape("turtle")
    pen.speed(5)
    result = []
    file = open("f://py_test.txt",'r')
    for line in file:
        print(line)
        result.append(list(map(float, line.split(','))))
    print(result)
    for i in range(len(result)):
        pen.color((result[i][3], result[i][4],result[i][5]))
        pen.fd(result[i][0])
        if result[i][1]:
            pen.rt(result[i][2])
        else:
            pen.lt(result[i][2])
if __name__ == '__main__':
    main()
其中的result.append(list(map(float, line.split(','))))
出现问题,原因是在float()转换字符串时,不能为空串或者‘\n’,否则就会报错

你可能感兴趣的:(python)