right adjusted strings containing umlauts

Kurt Mueller kurt.alfred.mueller at gmail.com
Thu Aug 8 10:23:46 EDT 2013


I'd like to print strings right adjusted.
( Python 2.7.3, Linux 3.4.47-2.38-desktop )

from __future__ import print_function
print( '>{0:>3}<'.format( 'a' ) )
>  a<

But if the string contains an Umlaut:
print( '>{0:>3}<'.format( 'ä' ) )
> ä<

Same with % notation:
print( '>%3s<' % ( 'a' ) )
>  a<
print( '>%3s<' % ( 'ä' ) )
> ä<

For a string with no Umlaut it uses 3 characters, but for an Umlaut
it uses only 2 characters.

I guess it has to to with unicode.
How do I get it right?


TIA
-- 
Kurt Mueller




More information about the Python-list mailing list