Using Python Print Statement in Dynamo

 

As of Dynamo 1.2, it’s still not possible to add additional OUT ports, but I did figure out a trick to redirect print( ) so you can “log” them.

It doesn’t actually stream it in the way a stdout typically would, but it does store all the data printed, and then you can assign the value to your OUT output.

In the absence of a debugger, I tend to add print statements all over the place when I am troubleshooting python , so I find this very helpful.

 

 

 

 

 

 

 

 

 

 

 

import sys

sys.path.append(r'C:Program Files (x86)IronPython 2.7Lib')

import time

from StringIO import StringIO

output = StringIO()

sys.stdout = output

t1 = time.time()

print('Starting Test')

print('=============')

print('1')

print('2')

print('3')

duration = time.time() - t1

print('Finished in {} seconds'.format(duration))

OUT = output.getvalue()
...
Read more

Leave a Comment