python SyntaxError: unexpected EOF while parsing

痞子三分冷 提交于 2019-12-25 07:48:35

问题


So I have this code

m, b = eval(input())

the aim is to have a whole bunch of comma separated values 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


回答1:


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(","))


来源:https://stackoverflow.com/questions/5306308/python-syntaxerror-unexpected-eof-while-parsing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!