Re: [Python.NET] Error in calling Python class method from C#

Stefan Schukat <[email protected]> Thu, 26 Apr 2018 11:24:14 +0000
Newsgroups gmane.comp.python.dotnet
Message-ID <19A216758DA7374193F26E107EDA37EA01ABC841C3@Exchange2010.dspace.de>
Hello,

you missed either @staticmethod decorator or the self argument for the Initialize method.

    Stefan

From: PythonDotNet [mailto:[email protected]] On Behalf Of techi eth
Sent: Wednesday, April 25, 2018 2:38 PM
To: A list for users and developers of Python for .NET <[email protected]>
Subject: [Python.NET] Error in calling Python class method from C#

Hi,

I am facing issue while calling python class function in C# programme. Can anyone give me hint what is wrong in below programme.While running I am getting error in invoking Initialize() function of class.

Python module <Class.py> :
def test():
 print "Test called"
 return 1

class ClassTest:
  def __init__(self)

  def Initialize ():
   print " Initialize called"
   return 1

  @staticmethod
  def Execute():
   print "Execute called"
   return 1

C# Console Programme code snapshot :
PythonEngine.Initialize();
            using (Py.GIL())
            {
                PyObject testClassModule = PythonEngine.ImportModule("Class");

                //Calling module method
                PyObject result = testClassModule.InvokeMethod("test");
                Console.WriteLine("Test method result = {0}", result.ToString());

                PyObject classTest = testClassModule.GetAttr("ClassTest");
                classTest.InvokeMethod("Initialize "); -----------------------------> Error
                classTest.InvokeMethod("Execute");
           }
            PythonEngine.Shutdown();

_________________________________________________
Python.NET mailing list - [email protected]
https://mail.python.org/mailman/listinfo/pythondotnet