Python Editor_Input

Its a relativly simple thing I am stuck with
I cannot use multiple inputs in Python editor. For example just x = IN works, but if I use x=IN[0] , y=IN[1], then I get error.

The error is that you’re trying to iterate over a list but you’re only providing a singleton. Are you sure intB is a list?


my bad, you are correct. Could you please guide me how could I input a single Variable, Interger inside Pyhon IN node ? I tried IN()… doesnt work either :confused:

@hassan.orion you already did that by declaring “intB=IN[0]”, assuming that intB is a single variable (an integer in your case).

1 Like

As @goncalogbastos mentioned, your input is whatever you provide. You declare it as intB so intB is a singleton. The problem is that you then say for x in intB, which means for each item x within list intB, but intB is not a list to iterate through. You want to get rid of the for loop and use intB instead of x.

1 Like

As an aside, if you’re going to have multiple if statements in your loop, with the intention of only one of those conditions being satisfied, you should use if and elif. The reason is that if you only use if, the code will go through and check every single condition, if you use one if followed by elifs, it will stop as soon as one of those conditions is satisfied.
More of an explanation and a diagram towards the bottom of this page here.


To add to the suggestions, for most of my python based custom nodes I use these functions to force singletons into a list whenever iteration is involved:

# Define list/unwrap list functions
def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

def uwlist(input):
    result = input if isinstance(input, list) else [input]
    return UnwrapElement(result)

# Preparing input from dynamo to revit
element    = IN[0]
elements = tolist(IN[0])
uw_list  = uwlist(IN[0])
1 Like