-_RunPythonScript crashes in V5

I am experiencing consistently-repeatable crashes with 5.14.522.8390, specifically when interpolating strings within _-RunPythonScript. That seems crazy, but I’ve completely reinstalled Rhino, and the issue persists, even in safe mode with only RhinoScript and RhinoDLR_Python being allowed to load. So I’m wondering if anyone would be willing to paste the following into the Macro Editor or a toobar button command, and see if it crashes for you as well:

-_RunPythonScript (
print('the answer is %s' % 42)
)

I’m on win10 pro x64, and find that this issue does not occur when using the Rhino 6 beta. I sent in an error report with more details than this but didn’t hear anything back yet, so will appreciate if someone can please try running this, so I can tell whether it seems machine-specific.

Seems to be working here via MacroEditor (I’m on Win 8.1 though).

-_RunPythonScript (
print('the answer is {}'.format(42))
)

also seems to be working.

–Mitch

The error happens because 42 is an integer and you’re using %s which should be used for a string. Here are a number of options that you have.

If the response is always an integer then you should use:

print('the answer is %d' % 42)

To handle any number you can use:

print('the answer is %f' % 42)

If you want to use %s then convert the number to string:

print('the answer is %s' % str(42))

Finally you can use @Helvetosaur’s suggestion and let Python take care of formatting.

Thanks guys, at least it’s good to know this seems localized to my machine. For what it’s worth Mostapha, it is fine to use %s with any object in python (see the conversion types table in section 5.6.2 here), and all of your examples crash similarly on my machine (incidentally, the %d one is a worse crash, even exiting out of the debugger completely). Interestingly, I’m unable to get the format() method to crash, but then I guess that would involve a very different code path.

This type of behavior is what I might expect to see when strings are passed between different C runtimes, but since this appears to be localized to my machine (and this morning, I’ve done another complete reinstall, using a freshly-downloaded installer, with the crashes persisting, on both x86 and x64 rhino), I am thinking there must be something wrong with the runtimes on my machine.

Yes. I did a number of tests and you’re right. Didn’t know about the flexibility of %s. Thanks.