Passing variables to and between Python - script components

I’m having trouble passing variables between Python scripts. In my minimal working example, I group variables into a dictionary and pass it on to the next script. However, when it arrives, the datatype has changed to a string.

I attempted to use type hints, but dictionaries are not available. Previously, As a workaround I used the json module to pass the variable as a string through dumps() and reads(), but this method only works if the data is json-serializable, which is not always the case.

Any guidance on how to pass it on properly is much appreciated.

Have a look at this old example:

Nice, this works very well. Am I correct in assuming, that this works independent of the datatype within the tuple?

For curious future readers, passing on the data as:

(dict,)

works.

1 Like

I would assume so. Note that this tuple wrapping hack is used to work around the fact that a “dictionary that is passed as output from a component will be seen as enumerable … This means that only the keys will be resolved” i.e. only the keys are output:

And that one may also structure the data in a class (see the example by Giulio in the first link), which for other cases may be more appropriate (e.g. cases where you’re already working with classes and not dictionaries). Also note that one can pass lists of dicts/classes if one sets the receiving component parameter access to List Access.

1 Like