Python Cookbook学习记录 ch1_3_2013/10/21
摘要:
1.3测试一个对象是否是字符串如果让我写代码,第一反应肯定会采用书中提到的的槽糕的类型测试,使用type(),但是这可能导致Unicode码不能通过测试,甚至任何str子类都不行。>>> def isExactlyAString(anobj): return type(anobj) is type('')>>> print isExactlyAString('abc')True>>> print isExactlyAString(u'abc')False书中推荐方法如下>>> 阅读全文
posted @ 2013-10-21 22:53 七海之风 阅读(210) 评论(0) 推荐(0)
浙公网安备 33010602011771号