【问题标题】:Object initialization in PythonnetObject initialization in Pythonnet
【发布时间】:2022-12-01 21:15:34
【问题描述】:

Let's assume I've the following C# class:

public class Test
{
    public double X;
    public double Y;
}

Using IronPython 2.7 I was able to generate an object and initializes the fields using object initialization:

obj = Test(X = 1.0, Y = 2.0)

See as well the following question Object initialization in IronPython

Using CPython 3.9.7 and Pythonnet 3.01 the above code returns the following error:

TypeError: No method matches given arguments for Test..ctor: ()

As workaround I can use the following code:

obj = Test()
obj.X = 1.0
obj.Y = 2.0

But I would like to use object initialization.

【问题讨论】:

    标签: c# ironpython python.net object-initializers


    【解决方案1】:

    Not sure if I get your question, but try this:

    Test test = New Test(); || var test = New Test(); then test.x = whatever;

    【讨论】:

      猜你喜欢
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 2018-08-26
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-14
      相关资源
      最近更新 更多