def func(str1, method, width, fillchar): if isinstance(str1, str): str1 = unicode(str1, "UTF-8") assert isinstance(str1, unicode) two_width_count = len([s1 for s1 in str1 if is_wide_char(s1, 0)]) return getattr(str1, method)(width - two_width_count, fillchar)
def get_width(str1): c = 0 for s1 in str1: c += (2 if is_wide_char(s1, 0) else 1) return c