Python NameError from contents of a variable

百般思念 提交于 2019-12-02 07:25:59

You're using input where you need to be using raw_input. input evaluates the string that it's passed. raw_input gives you a string, which is what you want.

Note that this only applies in Python 2. In Python 3, raw_input is no longer available and input is the equivalent of Python 2's raw_input. In Python 2, input is equivalent to eval(raw_input)

when you use the input() to input the newBlock , the parser regards the newBlock as the variable instead of string. so you need to use raw_input

see the ref of the input()

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