def lenNg(iterable):
"""Redefining len here so it will be able to work with non-ASCII characters
"""
if isinstance(iterable, bytes_type) or isinstance(iterable, unicode_type):
unicode_data = obj2unicode(iterable)
if hasattr(unicodedata, 'east_asian_width'):
w = unicodedata.east_asian_width
return sum([w(c) in 'WF' and 2 or 1 for c in unicode_data])
else:
return unicode_data.__len__()
else:
return iterable.__len__()
评论列表
文章目录