RevitPythonShell 用户输入 raw_input 错误

RevitPythonShell user input raw_input error

有人知道如何修复 RevitPythonShell 2018.1.0.0 中的这个错误吗?

enter image description here

你在工作 python 2.x 还是 3.x?

在终端上查看:python -V

下面的代码用于 python 2.x(对于 python 3 使用输入而不是 raw_input):

answer = ''
while not answer:
    answer = raw_input("bunny rabbits lay eggs (y,n)? ").rstrip().lower()

@GTN,看起来 运行 和 shell 的代码正试图将该行解析为代码。这可能是由于它试图弄清楚您的输入是什么。我记得我第一次创建 RPS 时对所有这些感到非常困惑。

相反,尝试这样做:

print("bunny rabbits lay eggs? yes/no")
answer = raw_input()

编辑:我查过了。没用。

这是一个使用表单的解决方案:

import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Drawing import Point
from System.Windows.Forms import Form, TextBox, Button, Label, TableLayoutPanel, DockStyle, DialogResult, AnchorStyles


class InputBox(Form):
    def __init__(self, question):
        self.Text = question

        self.tlp = TableLayoutPanel()
        self.tlp.RowCount = 3
        self.tlp.ColumnCount = 1
        self.tlp.Dock = DockStyle.Fill

        self.label = Label()
        self.label.Text = question
        self.label.AutoSize = True
        self.label.Dock = DockStyle.Fill
        self.label.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom
        self.tlp.Controls.Add(self.label)

        self.answer = TextBox()
        self.answer.Dock = DockStyle.Fill
        self.answer.AutoSize = True
        self.answer.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom
        self.tlp.Controls.Add(self.answer)

        self.ok = Button()
        self.ok.Text = "OK"
        self.ok.AutoSize = True
        self.ok.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom
        self.ok.DialogResult = DialogResult.OK
        self.tlp.Controls.Add(self.ok)

        self.Controls.Add(self.tlp)

def raw_input(question):
    input_box = InputBox(question)
    result = input_box.ShowDialog()
    if result == DialogResult.OK:
        return input_box.answer.Text

print raw_input("bunny rabbits lay eggs??")