I am using python format
method to align East Asian Wide (EAW) characters in my terminal display. The following python3 code illustrates my problem.
ZH_STRING1 = "東京大学"
ZH_STRING2 = "麻将"
print(">" + "01234567" + "<")
print(">" + format(ZH_STRING1, ">4") + "<")
print(">" + format(ZH_STRING2, ">4") + "<")
print("---")
print("Length: ", len(ZH_STRING2))
The terminal output (see image below) shows that EAW character width is twice the width of an ordinary character, while the len
function return the correct number of characters (one for each ideograph).
The python format
function evaluate ZH_STRING1
length as 4 and ZH_STRING2
length as 2, and the format
function adds two space characters to make the alignment. Unfortunately, the different width between EAW and space characters messes the terminal output.
So, how can I het the correct aligment?