Chr*_*row 8 python google-app-engine types
我正在尝试确保对象是Python中的字符串类型(对于谷歌应用引擎).我正在这样做,以便我可以将其更改为db.Text类型,如果它超过500字节.但是,我一直收到错误:TypeError 'unicode' object is not callable
if type(value) in types.StringTypes and len(value) > 499:
value = db.Text(value)
setattr(entity, key, value)
Run Code Online (Sandbox Code Playgroud)
如果对象的类型是字符串,我应该用什么来测试?
你为什么打电话types.StringTypes?这是一个元组:
>>> types.StringTypes
(<type 'str'>, <type 'unicode'>)
Run Code Online (Sandbox Code Playgroud)
使用isinstance(value, types.StringTypes) and len(value) > 499