本文整理汇总了C#中PyObject.HasAttr方法的典型用法代码示例。如果您正苦于以下问题:C# PyObject.HasAttr方法的具体用法?C# PyObject.HasAttr怎么用?C# PyObject.HasAttr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyObject
的用法示例。
在下文中一共展示了PyObject.HasAttr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintBall
private static string PrintBall(PyObject ball)
{
string name = "?";
if (ball.HasAttr("name"))
name = ball.GetString("name");
double x = ball.GetFloat("x");
double y = ball.GetFloat("y");
double z = ball.GetFloat("z");
double mass = ball.GetFloat("mass");
double radius = ball.GetFloat("radius");
var builder = new StringBuilder();
builder.AppendLine("ball id " + ball.Get("id"));
builder.AppendLine("\tname: " + name + "\t mass: " + mass + "\t radius: " + radius);
builder.AppendLine("\txyz: [" + Math.Round(x) + ", " + Math.Round(y) + ", " + Math.Round(z) + "]");
return builder.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");
}
}