Formatting string with accented characters for printing

Jerry Rocteur jerry.rocteur at gmail.com
Sun Jan 18 11:04:57 EST 2015


Hi,

When I try and format output when there are accented characters the
output does not look right.

e.g.

27 Angie Dickons                       67,638
28 Anne MÉRESSE                 64,825

So the strings containing accented characters print one less than
those that don't.

I've tried both:

    print '{0:2} {1:25} {2} '.format( cnt, nam[num].encode('utf-8'),
steps[ind1])
    print "%3d %-25s %-7s" % ( cnt, nam[num].encode('utf-8'), steps[ind1])

I've searched but I can't see a solution..

I guess it is the way I'm printing nam[num].encode('utf-8') perhaps I
have to convert it first ?

Can someone please help.

Thanks

-- 
Jerry Rocteur

Jerry at rocteur.com



More information about the Python-list mailing list