You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to convert from List to PyList and back without losing type information.
// this works:int[]values2=newint[]{1,2,3};varpyvalues2=values2.ToPython();pyvalues2.As<int[]>();// this does not work.List<int>values=newList<int>{1,2,3};varpyvalues=values.ToPython();pyvalues.As<List<int>>();// unable to convert back to List<int>
It seems ToPython will just take any IEnumerable or IList and turn it into a python list. Even though it is not generally possible to convert it back. In this case I'd rather keep it as the original type, because eventually I'll need to get it back to C#.
I understand why the current behavior makes things easier, but it would be great if it was possible to disable or alter this behavior.
I agree, the whole conversion story of Python.NET is currently quite inconsistent. Before we apply more band-aids, I'd like to have an overall plan, though, s.t. if we have to break the API we make it count :)
Essentially, we need a set of wrapping/unwrapping functions and additionally a (separate) set of functions for conversion (for convenience).
Activity
filmor commentedon Jul 10, 2019
I agree, the whole conversion story of Python.NET is currently quite inconsistent. Before we apply more band-aids, I'd like to have an overall plan, though, s.t. if we have to break the API we make it count :)
Essentially, we need a set of wrapping/unwrapping functions and additionally a (separate) set of functions for conversion (for convenience).
rmadsen-ks commentedon Jul 10, 2019
I think this could be done without breaking the API.
I was thinking something in the style of:
lostmsu commentedon Sep 23, 2021
The particular issue with
List<T>should have been fixed in 3.0