Ive been trying to start to learn python… It’s going fantastic
Im trying to convert ints to strings in a list, without using existing nodes, i wanted to try to write as much in Python, just to get the hang of Python.
When i convert it to a string, a decimal gets added and i’m not sure why…
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# The inputs to this node will be stored as a list in the IN variables.
a = [round(num,0) for num in IN[0]]
b = [str(x) for x in [round(num,0) for num in IN[1]]]
OUT = a,b
I am not sure how to handle this, could anyone help me out with this?
When i try this in powershell it works as i intend:
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# The inputs to this node will be stored as a list in the IN variables.
a = [round(num,0) for num in IN[0]]
b = [str(int(round(x))) for x in IN[1]]
OUT = a,b
it also looks like you are using ironPython here, so there could be differences in the implementation there as well, or some marshaling going on between ironPython and Dynamo.
In a newer version of Dynamo you can try Cpython3 and see what you get - it’s important to compare apples to apples (ie the version and implementation of Python)
I had tried at the same time, you can grant the solution to Mr. Nick (He gave you, the reason, not me)
Hello, if the slight digression is possible
the type is not returned?
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# The inputs to this node will be stored as a list in the IN variables.
a = [round(num,0) for num in IN[0]]
b = [str(int(round(x))) for x in IN[1]]
c=type(a)
d=type(b)
e=type(a[0])
f=type(b[0])
OUT = a,b,c,d,e,f
Cordially
christian.stan
edit:
I’m really stupid, sorry, Mr. Nick had already given the answer above, sorry
To add to the options discussed here, in Python you can use the rstrip method with “.” to split. Then index the result at index 0. For unsplit strings you will get the whole outcome and for those that got split you will get the leading portion.