本文整理汇总了C#中PyObject.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# PyObject.ToString方法的具体用法?C# PyObject.ToString怎么用?C# PyObject.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyObject
的用法示例。
在下文中一共展示了PyObject.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPyValue
private string GetPyValue(PyObject attr)
{
switch (attr.GetPyType())
{
case PyType.FloatType:
case PyType.DerivedFloatType:
return ((double) attr).ToString();
case PyType.IntType:
case PyType.LongType:
case PyType.DerivedIntType:
case PyType.DerivedLongType:
return ((long) attr).ToString();
case PyType.BoolType:
case PyType.DerivedBoolType:
return ((bool) attr).ToString();
case PyType.StringType:
case PyType.UnicodeType:
case PyType.DerivedStringType:
case PyType.DerivedUnicodeType:
return (string) attr;
case PyType.MethodType:
var x = attr.Attribute("im_func").Attribute("func_code");
var name = (string) x.Attribute("co_name");
var argCount = (int) x.Attribute("co_argcount");
var args = string.Join(",", x.Attribute("co_varnames").ToList<string>().Take(argCount).ToArray());
return name + "(" + args + ")";
default:
return attr.ToString();
}
}
示例2: PyException
public PyException(IntPtr type, IntPtr value, IntPtr traceback)
{
TypeObject = new PyObject(type);
ValueObject = new PyObject(value);
TracebackObject = new PyObject(traceback);
TypeObject.IncRef();
ValueObject.IncRef();
TracebackObject.IncRef();
Type = TypeObject.GetString("__name__");
if (ValueObject.IsString)
Value = PyString.GetValueInternal(ValueObject.Pointer);
else if (ValueObject.HasAttr("message"))
Value = ValueObject.GetString("message");
else // use Py_Repr to atleast get some information
Value = ValueObject.ToString();
CallStack = new List<PyTraceback>(5);
var cur = TracebackObject;
while (cur != null && cur.IsValid && !cur.IsNone)
{
CallStack.Add(new PyTraceback(cur));
cur = cur.Get("tb_next");
}
}