Import division from __future__

Hi All,

I get an error when I try to use division from __future__

It works in the console:

Any ideas why?

Thanks.

import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
from __future__ import division

a=4/3.0

OUT=a

6. Simple statements — Python 2.7.18 documentation
A future statement must appear near the top of the module. The only lines that can appear before a future statement are:

the module docstring (if any),
comments,
blank lines, and
other future statements.

Hi @salvatoredragotta
This seems to be a weird paradox caused by Dynamo’s python engine lack of standard library.

  1. import future needs to be at top of your code
  2. you must add ironpython lib to sys.path before you can import future

Link above explains why the error, and why it works on the python interactive interpreter.
Most other cases would also work as the default library would already be loaded into the module before you hit the first line.

Unless someone else has other ideas, the easiest solution I can think of, is just cast on of your arguments into a float before you use it, and that will give you true division instead of floor division.
You can see more details about the division types and why it was changed in the pep below:

thanks @Gui_Talarico

it is a paradox :slight_smile:

Is there a way to have Dynamo point at the ironpython library automatically?

Would it be a request for the Dynamo Developers?

I personally think it should be shipped and loaded by default as well, but I guess they decided not to.

You can post it as an issue on github, or try to do it yourself and compile your own dynamo version.

They python engine is create here:

You can add the library to the Engine object as described here stackoverflow answer.