# Transferring data between Python components

**URL:** <https://discourse.mcneel.com/t/transferring-data-between-python-components/193011>\
**Category:** Grasshopper\
**Tags:** windows, python, python3\
**Created:** [October 15, 2024, 1:49am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011 "2024-10-15T01:49:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![YCoCg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ycocg/32/650725_2.png) [@YCoCg](https://discourse.mcneel.com/u/YCoCg)\
**Post date:** [October 15, 2024, 1:49am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/1 "2024-10-15T01:49:06Z")

</div>

I am having trouble understanding how I am supposed to handle inputs/outputs for the Python 3 component in Rhino 8. It’s different to Rhino 7 where Python lists automatically become Grasshopper lists.  
Searching around I found that there is a hidden Avoid Marshalling Outputs option ([link](https://discourse.mcneel.com/t/invalidcastexception-dictionary-in-rhino-8-gh-python3-script-component/175310/7)) although I’m not sure how to also have the python component simultaneously output Grasshopper lists of objects (there are multiple outputs and usually I would be outputting both geometry and Python data).

At the moment I see two suboptimal solutions:

- Not marshal the outputs but have an additional component to marshal any outputs desired.
- Wrap the python objects intended to be inputted into other python components in a custom class.

Any better solutions?

---

<div class="post-metadata">

**Author:** ![James\_Parrott](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/james_parrott/32/713265_2.png) [@James\_Parrott](https://discourse.mcneel.com/u/James_Parrott)\
**Post date:** [October 15, 2024, 8:26am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/3 "2024-10-15T08:26:31Z")

</div>

Are you sure the mode of the output param is set to list or tree?

---

<div class="post-metadata">

**Author:** ![YCoCg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ycocg/32/650725_2.png) [@YCoCg](https://discourse.mcneel.com/u/YCoCg)\
**Post date:** [October 15, 2024, 11:15am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/4 "2024-10-15T11:15:09Z")

</div>

Where is this setting? I don’t see it when I right click the outputs or the component.

---

<div class="post-metadata">

**Author:** ![eirannejad](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eirannejad/32/775509_2.png) [@eirannejad](https://discourse.mcneel.com/u/eirannejad)\
**Post date:** [October 15, 2024, 5:33pm UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/5 "2024-10-15T17:33:19Z")

</div>

@YCoCg Would it be possible to share a small example that replicates the problem you are having?

Python 3 parameter marshaling is documented here. Let me know if there is anything missing or is confusing and I can improve:

> **[Grasshopper Scripting: Python](https://developer.rhino3d.com/guides/scripting/scripting-gh-python/#marshalling)**
>
> Provides detailed information on Python scripting in Grasshopper

---

<div class="post-metadata">

**Author:** ![YCoCg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ycocg/32/650725_2.png) [@YCoCg](https://discourse.mcneel.com/u/YCoCg)\
**Post date:** [October 16, 2024, 1:19am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/6 "2024-10-16T01:19:19Z")

</div>

[simple example marshalling 1.gh](https://discourse.mcneel.com/uploads/short-url/udsdNfVXDRL1vsyKyVxnkxvtL6S.gh) (16.0 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/c/6/7c62e50731fe9d68f356caafe45f374020691322.png)

I am trying to have the same functionality as is provided in Rhino 7, the wrapping method I mentioned and include in the example file seems to be the closest but I’d rather not need a class for this.

---

<div class="post-metadata">

**Author:** ![James\_Parrott](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/james_parrott/32/713265_2.png) [@James\_Parrott](https://discourse.mcneel.com/u/James_Parrott)\
**Post date:** [October 16, 2024, 8:35am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/7 "2024-10-16T08:35:03Z")

</div>

Oh sorry - I’m not able to check at the moment. Do you see it on the inputs?

I remember passing dictionaries between Python components, without Grasshopper converting them into a .Net implementation, by returning them inside a list, instead of just as they are.

---

<div class="post-metadata">

**Author:** ![YCoCg](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/ycocg/32/650725_2.png) [@YCoCg](https://discourse.mcneel.com/u/YCoCg)\
**Post date:** [October 16, 2024, 8:51am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/8 "2024-10-16T08:51:57Z")

</div>

The second example in my screenshot is basically that, I set the D output in Python to a list of dictionaries. No matter how much I wrap them, all the elements seem to be converted to something other than Python objects, preventing the second python script from reading it directly.

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [October 16, 2024, 8:55am UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/9 "2024-10-16T08:55:24Z")

</div>

> [@James\_Parrott](#):
>
> I remember passing dictionaries between Python components, without Grasshopper converting them into a .Net implementation, by returning them inside a list, instead of just as they are.

> [@YCoCg](#):
>
> No matter how much I wrap them…

The list wrapping trick does indeed not seem to work with the new CPython editor, however the Grasshopper `ObjectWrapper` does appears to still do the trick:

 ![2024-10-16 10_52_46-Grasshopper - 241016_CPython_PassDict_00_](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/6/e/2/6e23b02fc0c43ccfcbb8b1fa581dc025f853384a.png)  
[241016\_CPython\_PassDict\_00.gh](https://discourse.mcneel.com/uploads/short-url/y7oMejDanls5wkSMEX9Mz3Fj40f.gh) (2.2 KB)

---

<div class="post-metadata">

**Author:** ![eirannejad](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eirannejad/32/775509_2.png) [@eirannejad](https://discourse.mcneel.com/u/eirannejad)\
**Post date:** [October 18, 2024, 7:33pm UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/10 "2024-10-18T19:33:21Z")

</div>

Okay I see where the bug is. Working on a fix ASAP:

[RH-84379](https://mcneel.myjetbrains.com/youtrack/issue/RH-84379) CPython marshalling error

---

<div class="post-metadata">

**Author:** ![eirannejad](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/eirannejad/32/775509_2.png) [@eirannejad](https://discourse.mcneel.com/u/eirannejad)\
**Post date:** [October 18, 2024, 8:32pm UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/11 "2024-10-18T20:32:33Z")

</div>

@YCoCg Got this issue resolved and put a fix in the next 8.13 SRC (I decided to push this out earlier so you don’t have to manually wrap the outputs in `GH_ObjectWrapper`.

Also created a unit test to make sure this list\_with\_dictionaries case is always tested

 ![Rhino_mg2Rv6pOhe](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/b/7/a/b7a3bb414419c705ab6849e84bae83732d7f9a50.png)

---

<div class="post-metadata">

**Author:** ![brian](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/brian/32/504171_2.png) [@brian](https://discourse.mcneel.com/u/brian)\
**Post date:** [October 29, 2024, 11:31pm UTC](https://discourse.mcneel.com/t/transferring-data-between-python-components/193011/12 "2024-10-29T23:31:54Z")

</div>

[RH-84379](https://mcneel.myjetbrains.com/youtrack/issue/RH-84379) is fixed in [Rhino 8 Service Release 13](https://www.rhino3d.com/download/rhino/8/latest)
