开发者

python SyntaxError: unexpected EOF while parsing

开发者 https://www.devze.com 2023-02-16 16:37 出处:网络
So I have this code m, b = eval(input()) the aim is to have a whole bunch of comma separated val开发者_Python百科ues inputted and then have python unpack the tuple into the variables

So I have this code

m, b = eval(input())

the aim is to have a whole bunch of comma separated val开发者_Python百科ues inputted and then have python unpack the tuple into the variables

but when i run i get this error

    x, y = eval(input())
  File "<string>", line 1
    1,2

           ^
SyntaxError: unexpected EOF while parsing

what did i do wrong?

im using python 3


You should not use eval for things like this. It will be impossible to write it in a way such that the user can't break it (by mistake or on purpose). Do something like this instead:

data = input()
m, b = (int(var) for var in data.split(","))
0

精彩评论

暂无评论...
验证码 换一张
取 消