Trying out the new "Ruby Mode" in Python 3.9, but am having trouble getting it working:
Simple script in mymodule
:
puts "Hello World"
Expected output when executing the file in ruby mode ("rb") was for "Hello World" printed on stdout, but I'm getting an error:
>>> with open("mymodule", mode="rb") as f:
... for line in f:
... exec(line)
...
Traceback (most recent call last):
File "<string>", line 1
puts "Hello World"
^
SyntaxError: invalid syntax
It looks like the lines are being correctly parsed as rb"ruby style lines"
, so it's clearly not open
at fault:
>>> line.strip() == rb'puts "Hello World"'
True
What's wrong here? That must be a bug in exec
, right?
Running a file in Ruby mode has to be lead by a Ruby shebang. Try using:
#!/usr/april/fools/ruby
puts "Hello World"