Python utf-8, howto align printout
Posted
by Fredrik
on Stack Overflow
See other posts from Stack Overflow
or by Fredrik
Published on 2010-03-19T11:54:19Z
Indexed on
2010/03/19
12:11 UTC
Read the original article
Hit count: 383
Hi,
I have a array containing japanese caracters as well as "normal". How do I align the printout of these?
#!/usr/bin/python
# coding=utf-8
a1=['??', '???', 'trazan', '??', '????']
a2=['dipsy', 'laa-laa', 'banarne', 'po', 'tinky winky']
for i,j in zip(a1,a2):
print i.ljust(12),':',j
print '-'*8
for i,j in zip(a1,a2):
print i,len(i)
print j,len(j)
Output:
?? : dipsy
??? : laa-laa
trazan : banarne
?? : po
???? : tinky winky
--------
?? 6
dipsy 5
??? 9
laa-laa 7
trazan 6
banarne 7
?? 6
po 2
???? 12
tinky winky 11
thanks, //Fredrik
© Stack Overflow or respective owner