Does anybody know how to fix this error in RevitPythonShell 2018.1.0.0?
Asked
Active
Viewed 149 times
2 Answers
0
Are you working python 2.x or 3.x?
Check on the terminal: python -V
The below code is for python 2.x (for python 3 use input instead of raw_input):
answer = ''
while not answer:
answer = raw_input("bunny rabbits lay eggs (y,n)? ").rstrip().lower()

Mahsa Hassankashi
- 2,086
- 1
- 15
- 25
-
Thanks Mahsa. I use python 2.x. It's what RPS is runny on. raw_input works fine in any other environment. just not on RPS for some reasons. Same applies for the code you shared. – GTN Apr 18 '20 at 16:24
-
@GTN Maybe it is because of this character '>' , please replace 'bunny rabbits lay eggs (y,n)?' with your sentence. – Mahsa Hassankashi Apr 18 '20 at 16:38
0
@GTN, it looks like the code that is running the shell is trying to parse the line as code. That is probably due to how it tries to figure out what your input was. I remember being very confused with all of this when I first created RPS.
Instead, try doing this:
print("bunny rabbits lay eggs? yes/no")
answer = raw_input()
EDIT: I checked. It doesn't work.
Here's a solution that uses Forms:
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??")

Daren Thomas
- 67,947
- 40
- 154
- 200
-
1Thanks Daren. I tried and it doesn't work either. Are there any other workarounds to prompt for and take user inputs in RPS? – GTN Apr 18 '20 at 16:25