Python NameError from contents of a variable

前端 未结 2 1159
慢半拍i
慢半拍i 2021-01-25 01:50

I\'ve been making a mod for the Raspberry Pi version of Minecraft and I\'m getting a very frustrating error every time I enter one of the commands in my program. Here\'s my code

相关标签:
2条回答
  • 2021-01-25 02:17

    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)))
    
    0 讨论(0)
  • 2021-01-25 02:24

    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)

    0 讨论(0)
提交回复
热议问题