def width(s): w = 0 for c in s.decode(locale.getpreferredencoding()): if unicodedata.east_asian_width(c) in ("W", "F"): w += 2 else: w += 1 return w