/// Get a member of this module by name. public PyObj GetMember(string attrName) { PyObj result; unsafe { var rawDict = CPython.PyModule_GetDict(obj); if (rawDict == null) { throw new NullReferenceException("Failed to get dict from module."); } var rawString = CPython.PyUnicode_FromString(attrName); if (rawString == null) { throw new NullReferenceException("Failed to create PyObject from string."); } var rawResult = CPython.PyDict_GetItem(rawDict, rawString); if (rawResult == null) { throw new NullReferenceException("Failed to get item by key."); } result = new PyObj(rawResult); } return(result); }
/// Create a PyObject from a string. public static PyStr FromString(string value) { PyStr result; unsafe { var rawResult = CPython.PyUnicode_FromString(value); if (rawResult == null) { throw new NullReferenceException("Failed to create PyObject from string."); } result = new PyStr(rawResult); } return(result); }