1

I'm trying to send an array/list to an IronPython method as argument.

I can pass a normal array or list (and it works), but then native methods like pop are not available on the Python side.

What is the best way to convert a C# List<> to an IronPython.Runtime.List?

I found the IronPython.Runtime.List.__new__ method but I don't know how to fill CodeContext and PythonType variables.

I found this for the other way around: passing Lists from IronPython to C#

1 Answer 1

0

Oops - found it. Just using an empty constructor():

public static IronPython.Runtime.List ToPythonList(this IEnumerable<object> list)
{
    var result = new IronPython.Runtime.List();

    foreach ( var item in list )
        result.append( item );

    return result;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.