python ValueError: invalid literal for float()

后端 未结 3 1978
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-06 04:23

I\'ve a script which reads temperature data:

def get_temp(socket, channels):

    data = {}
    for ch in channels:
        socket.sendall(\'KRDG? %s\\n\' %          


        
3条回答
  •  臣服心动
    2020-12-06 05:16

    Watch out for possible unintended literals in your argument

    for example you can have a space within your argument, rendering it to a string / literal:

    float(' 0.33')
    

    After making sure the unintended space did not make it into the argument, I was left with:

    float(0.33) 
    

    Like this it works like a charm.

    Take away is: Pay Attention for unintended literals (e.g. spaces that you didn't see) within your input.

提交回复
热议问题