I have code that references another module. Whenever I perform division in a function that is local to the current module it returns the result (float) perfectly, however, if I perform the exact same division in a function that is inside another module it does not. Everything I have read with Python states that if you use the / operator, it will return a float. If you use the // operator it will return an int.
See for yourself.
In a script copy the following code and adjust where the path for your scripts. You will need to rename the CommonScript reference to another script file name that you will also create.
import sys
sys.path.append(r'C:\Python Scripts')
from CommonScripts import *
def TestMeInThisScript(c):
print 'Calling from this script.'
print 'Passed value: ' + str(c)
print 'Calced value: ' + str(c / 3)
if __name__ == '__main__':
TestMeInThisScript(2)
TestMeInOtherScript(2)
In another script file (mine was called CommonScript) copy the following code:
Hi Pascal - Thanks. It’s just odd that it works just fine inside the same file but when referencing the external file it does not. Sounds like a bug to me. It should work one way or the other in both locations. As a work around I just added the following prior to the calc:
Ah ok that explains it’s an underlying Python issue. I know Rhino uses IronPython which is stuck on 2.7. It sounds like 3.8 is the latest for Python and 3.4.0 beta for IronPython. Anyone know if Rhino 8 will move away from IronPython or implement IP 3.4.0 if it’s out of beta in time? Just curious.