I am trying to pass a static c# class into python using pythonnet. I am able to use scope.Set("person", pyPerson) similar to sample below. However in my case this is a utility (static) class and I get error that util does not contain testfn in sample below.
using Python.Runtime;
// create a person object
Person person = new Person("John", "Smith");
// acquire the GIL before using the Python interpreter
using (Py.GIL())
{
// create a Python scope
using (PyScope scope = Py.CreateScope())
{
// convert the Person object to a PyObject
PyObject pyPerson = person.ToPython();
// create a Python variable "person"
scope.Set("person", pyPerson); //<------ this works
scope.Set("util", Utility); //<------ Utility is a static class whose method I am trying to call
//and this does not work.
// the person object may now be used in Python
string code = "fullName = person.FirstName + ' ' + person.LastName"; //<--- works
code = "util.testfn();" //testfn is a static class, How do I do this ?
scope.Exec(code);`enter code here`
}
}