C# 可以在不同的按钮点击时调用python函数吗?

C# 可以在不同的按钮点击时调用python函数吗?,c#,python.net,C#,Python.net,我希望从winform.button1\u click\u event()中的python类调用函数1,然后从winform.button2\u click\u event()中的同一python类调用函数2。 注:函数2的数据依赖于函数1。 如何做到这一点 我不能使用IronPython,因为它不支持keras访问 Class.py def load_Model_data(self): #Some code def Predict(self): #some code

我希望从winform.button1\u click\u event()中的python类调用函数1,然后从winform.button2\u click\u event()中的同一python类调用函数2。 注:函数2的数据依赖于函数1。 如何做到这一点

我不能使用IronPython,因为它不支持keras访问

Class.py


  def load_Model_data(self):
    #Some code

  def Predict(self):
    #some code
Program.cs

void button1_Click(object sender, EventArgs e)
        {
           PythonEngine.Initialize();
            using (Py.GIL())
            {
                PyObject MyClass = PythonEngine.ImportModule("Class");

                Dynamic classTest = MyClass.GetAttr("ClassTest");
                               Dynamic tmp = classTest();
                tmp.load_Model_data;
           }

        }

void button2_Click(object sender, EventArgs e)
        {
            using (Py.GIL())
            {
                PyObject MyClass = PythonEngine.ImportModule("Class");
                Dynamic classTest = MyClass.GetAttr("ClassTest");
                               Dynamic tmp = classTest();
                tmp.Predict();
           }
        }

单击按钮2时,python代码中的值未更新。

错误是什么,请发布,因为如果我们不知道错误是什么,我们将无法帮助您。请在button2中的所有行上放置断点,然后单击,然后告诉我们它在哪一行中断,以及确切的异常是什么。@Chuchěxěŕon click button2 python代码中的变量没有新值。@hexagod我试图重现错误,这次我没有得到它,但是python代码中的变量没有新值。它的emptyglobal在类作用域变量的意义上,是的。我不知道python引擎的细节,但它的使用寿命可能也要比单击按钮的时间长。