Python.Runtime.PyObject.ToString C# (CSharp) Метод

ToString() публичный Метод

ToString Method
Return the string representation of the object. This method is the managed equivalent of the Python expression "str(object)".
public ToString ( ) : string
Результат string
        public override string ToString()
        {
            IntPtr strval = Runtime.PyObject_Unicode(obj);
            string result = Runtime.GetManagedString(strval);
            Runtime.XDecref(strval);
            return result;
        }

Usage Example

Пример #1
0
    public PythonException() : base()
    {
        IntPtr gs = PythonEngine.AcquireLock();
        Runtime.PyErr_Fetch(ref _pyType, ref _pyValue, ref _pyTB);
        Runtime.Incref(_pyType);
        Runtime.Incref(_pyValue);
        Runtime.Incref(_pyTB);
        if ((_pyType != IntPtr.Zero) && (_pyValue != IntPtr.Zero))
        {
            string type;
            string message;
            Runtime.Incref(_pyType);
            using (PyObject pyType = new PyObject(_pyType))
            using (PyObject pyTypeName = pyType.GetAttr("__name__"))
            {
                    type = pyTypeName.ToString();
            }

            Runtime.Incref(_pyValue);
            using (PyObject pyValue = new PyObject(_pyValue)) 
            {
                message = pyValue.ToString(); 
            }
            _message = type + " : " + message;
        }
        if (_pyTB != IntPtr.Zero)
        {
            PyObject tb_module = PythonEngine.ImportModule("traceback");
            Runtime.Incref(_pyTB);
            using (PyObject pyTB = new PyObject(_pyTB)) {
                _tb = tb_module.InvokeMethod("format_tb", pyTB).ToString();
            }
        }
        PythonEngine.ReleaseLock(gs);
    }
All Usage Examples Of Python.Runtime.PyObject::ToString