1

重复: 在python中检查类型的规范方法是什么?

如何在 IronPython 中检查类型相等性?

我需要 IronPython 中与以下 C# 代码等效的代码:

if (x.GetType() == typeof(xType))

或者

if (x is xType)
4

2 回答 2

3
from System import *
if x.GetType() == Type.GetType(xType):
于 2009-05-08T15:29:49.000 回答
0

说 C 是一个静态类,不是完全限定的,而是导入到 Iron python 脚本中的 x 是 C 的一个实例,而 ABC 是完全限定的名称

为什么这些不起作用?

x.GetType() == Type.GetType("A.B.C")

或者

x is Type.GetType("A.B.C")

或者

x is C

或者

x.GetType() == Type.GetType(C)
于 2009-07-08T20:36:19.353 回答