Print formatted Strings with Umlauts
"Martin v. Löwis"
martin at v.loewis.de
Thu Feb 12 08:10:40 CET 2004
Joerg Lehmann wrote:
> I am using Python 2.2.3 (Fedora Core 1). ...
> 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???
There is, but Fedora Core 1 does not use it. Instead, it uses an
encoding where an umlaut character needs two bytes (namely, UTF-8).
Changing site.py does not change the way your system represents
> What is the right way
> to print strings containing umlauts in a tabular way (same field width)?
As Jeff explains: In the specific case, using Unicode strings would
help. He is also right that, in general, it is very difficult to find
out how many columns a single character uses, as some characters have
width 0, and other characters have width 2 (in a mono-spaced terminal;
for variable-spaced output, adding space characters to achieve
formatting will never work reliably).
More information about the Python-list