Print formatted Strings with Umlauts

Amy G amy-g-art at cox.net
Wed Feb 11 16:36:24 EST 2004


Upgrading to 2.3 will probablt solve this problem.  I am using 2.3 and here
is what I get when I try it.

>>> a = 'äöü'
>>> len (a)
3

>>> b = '123'
>>> print "%-5s %-5s\n%-5s %-5s" % (a,a,b,b)

äöü   äöü
123   123




"Joerg Lehmann" <joerg.lehmann at mail.com> wrote in message
news:91317660.0402111249.4ccc6e24 at posting.google.com...
> I am using Python 2.2.3 (Fedora Core 1). The problem is, that strings
containing
> umlauts do not work as I would expect. Here is my example:
>
> >>> a = 'äöü'
> >>> b = '123'
> >>> print "%-5s %-5s\n%-5s %-5s" % (a,a,b,b)
> äöü äöü
> 123   123
>
> I would expect, that the displayed width of a or b is the same: 5
characters.
> I also see, that len(a) is 6 (2 bytes per umlaut), whereas len(b) is 3:
>
> >>> print len(a), len(b)
> 6 3
>
> I have tried to set the encoding in site.py to 'latin-1', but it did not
change
> my results. Is there no way to store umlauts in 1 byte??? What is the
right way
> to print strings containing umlauts in a tabular way (same field width)?
>
> Thanks!
> --
> Joerg Lehmann





More information about the Python-list mailing list