When will Python be updated to Rhino?

Hello folks,

I’m having a huge problem with python embed in rhino. I’m working with a dictionary, trying to run a loop on it but python 2.7 shows a non-sequencial values of the dictionary when I run this loop. It happens when I print all the dictionary, too. The sorted() function does not work in this case because I’m using numbers (floats,int) as strings. And when I sort it the number 10 comes before the number 4, for example.

I tested it in python 3.9, and it works as expected, the dictionary is shown as it’s written, the loop runs ok, the positions are all correct. I also tested it in python 2.7 outside rhino and it runs like IronPython IDE.
It is a python 2.7 issue.


Please, update python in rhino on the next versions, help us make better scripts.


On this job I will have to make an unconvinient workaround to run it as expected.

Hello,

You can use sorted(my_dict, key=float)

1 Like

Use an ordered dictionary, instead of the regular one. It preserves the order in which the keys are inserted. The standard dictionary is unordered and that is not different in Python 3!

from collections import OrderedDict

od = OrderedDict()
od["a"] = "apples"
od["b"] = "oranges"
od["c"] = "pears"

print od

You should also note that Rhino ships with IronPython, not CPython!

1 Like

This changed unofficially in Python 3,6 and officially in 3.7 - They found a way to make dictionaries quicker which incidentally preserved insertion order. They liked it so much they decided to keep it as part of the language!

Dictionnaires are really important in Python as every object and every name space keeps all its variables and methods in a dictionary so they are key to the performance of the whole language

3 Likes

Good to know! Thanks for pointing that out.

1 Like

Yes this would be great. There have been multiple postings from Rhino developers talking about possibly adding a Cpython interpreter without removing the Ironpython one, but with no definite plans, timescales or target Rhino version number.

1 Like

Seeing the efforts that are poured into coming up with creative workarounds, like for instance Hops, doesn’t render me too optimistic this will ever happen.

Incorporating Python 3 is actively being worked on for V8. Nothing to show yet, so this is just an empty promise right now.

5 Likes

CPython 3?

Yes, the current focus is for CPython 3

2 Likes

Uh, nice! :ok_hand:

Grasshopper 2, CPython 3, and Cycles X that would be a killer feature set for Rhino 8! :sunglasses:
I guess one can dream.

1 Like

Sorry about the CPython post assignment. When I type “python” in the “category” field, CPython comes together, the issue is with python, only.

Thanks for the advice with the ‘collections module’. I will try it.

Thanks for this solution. Worked like charm.

You forgot to add Metal to that combo :slight_smile:

4 Likes

The Rhino 8 WIP now contains support for CPython 3.

See Rhino 8 Feature: RhinoCode (CPython, CSharp)

3 Likes