Python vs ghPyhton, what to expect when converting one to the another?

So, I have a few codes written in Delphi, that demand a hellot of inputs from the user, that I made as a laboratory intern during college.

I spend a few hours in GH past weekend trying to see if I could grab this inputs in a semi-automatic way using grasshopper. I kinda got part of what I needed (I have now to isolate the info in some way to use as an input, but I think a few curve intersections and list item should do the trick, plus get all the other inputs).

Now comes the real question, I am dedicating some work into converting the Delphi codes (and fixing some bugs and optimizing some functions) to Python, the language I am more familiar with, but I started doing it using PyCharm, thinking that Python is Python, but now I found out that ghPython is actually IronPython.

What kind of errors can I expect? Are Python libraries converted to ghPython as well? Can I use and import a self made library or should the code include everything is needed on itself?

If you use pure Python (which means only libraries that are written in Python and without C bindings) it will behave the same. Usually problems appear when you need to use interop with C/C++ libraries.

Hello,

Also be aware that Ironpython is still on Python 2.7 so if you are used to Python 3 you will get the usual minor problems with print functions vs print statements, integer division, my_dict.iteritems(), et cetera.

You can use from __future__ import division, absolute_import, print_function before your other imports to reduce some of the pain, although I think division usually works as per Python 3 in Rhino and Grasshopper.

-Graham

1 Like

Thank you both for the heads up

I think I may be able to finish the correction from Delphi to Python during my lunch break today, if so I will be able to paste the code inside grasshopper and test it out tonight.

I will for sure have a lot more doubts as I move into the ghPython environment.