hello guys,
i wrote this script on python compiler but how to make the output as shown in the this code if i am using dynamo
if lst [s] [2] [z] > 5 :
print(“fixtures is”, inputfx)
print(“gpm is”, x)
print(“diameter is” , actual[s+1])
print(“velocity is” , lst[s+1][1][e])
print (“friction is”, lst[s+1][2][e])
else :
print(“fixtures is”, inputfx)
print(“gpm is” , x)
print(“diameter is”, actual[s])
print(“velocity is”, lst[s][1][z])
print(“friction is”, lst[s][2][z])
There is no easy way to do this. The one workaround I have used is to redirect stdout
to a .txt file.
import sys
filepath = IN[0] # Assuming you're feeding a file path into the first input
# e.g. r'C:\Users\User1\Documents\Temporary\print.txt'
stdout_original = sys.stdout
stdout_file = open(filepath, 'w')
sys.stdout = stdout_file
print 'example'
print 'other example'
sys.stdout = stdout_original
stdout_file.close()
I also found this other interesting method which redirects stdout
to StringIO()
which won’t require you to open a separate file, but would require you to split your ‘printed’ data from the rest of your output going downstream.
1 Like
If you’re looking to keep the results in Dynamo, then create variables and assign them to the output. Some sudo code:
if test
Variable1 = 1
Variable2 = 2
else
Variable1 = 3
Variable2 = 4
OUT = [Variable1, Variable2]
You can try the codes below, and link the OUT to a Watch Node.
import sys
from io import StringIO
sys.stdout = StringIO()
print("***Starting print***")
if lst [s] [2] [z] > 5 :
print(“fixtures is”, inputfx)
print(“gpm is”, x)
print(“diameter is” , actual[s+1])
print(“velocity is” , lst[s+1][1][e])
print (“friction is”, lst[s+1][2][e])
else :
print(“fixtures is”, inputfx)
print(“gpm is” , x)
print(“diameter is”, actual[s])
print(“velocity is”, lst[s][1][z])
print(“friction is”, lst[s][2][z])
print("***Ending print***")
sys.stdout.seek(0)
OUT = sys.stdout.read()
2 Likes