[Python.NET] Python class instance from C#
Denis Akhiyarov <[email protected]>
| Newsgroups | gmane.comp.python.dotnet |
|---|---|
| Message-ID | <CALxxJLSmfnxZMkyQKmqLGsu9MfndcxC7bAFWo2pztiY82wnpkQ@mail.gmail.com> |
Does anyone have an example of using Python.NET in embedding scenario for
creating an instance of a Python class/object, possibly with arguments
passed to __init__() and then using this instantiated class to call its
methods?
The workaround for me right now is calling Python wrapper function that
returns new instance of this class.
I have an example that does NOT work for me:
IntPtr pyobj = default(IntPtr);
IntPtr u_name = Runtime.PyUnicode_FromString(ModuleName);
IntPtr module = Runtime.PyImport_Import(u_name);
IntPtr pyclass = Runtime.PyObject_GetAttrString(module, ObjectName);
if (Runtime.PyCallable_Check(pyclass) == 1)
{
pyobj = Runtime.PyObject_CallObject(pyclass, pyargtuple);
}
IntPtr inst = Runtime.PyObject_Call(pyobj, IntPtr.Zero);
PyObject result = new PyObject(inst);
return result;
_________________________________________________
Python.NET mailing list - [email protected]
https://mail.python.org/mailman/listinfo/pythondotnet