【发布时间】:2013-03-28 12:07:29
【问题描述】:
我正在尝试将一些代码从 2 转换为 3 以及以下简单脚本
import types
from types import NoneType
结果
ImportError: 无法导入名称 NoneType
如何将上面的从 2 转换为 3?
【问题讨论】:
-
因为
NoneType只有一个实例,所以x is None完全等于isinstance(x, NoneType)。如果您根据None检查类型,则有问题。 -
@GarethLatty 对于元组用例很有用。
isinstance(json_compatible_basic_type_expected, (int, float, str, NoneType))
标签: python python-3.x porting