import unicodedata def get_char_width(c): data = unicodedata.east_asian_width(c) if data in ['Na', 'H']: return 1 else: return 2 def get_str_width(s): return sum([get_char_width(c) for c in s])