stepper_m stepper_m - 4 months ago 13
Python Question

Python print format umlaut align right

I am trying to print text aligned right containing a german umlaut. This is, what the python interpreter produces:

>>> print "----\n{:>4}\n{:>4}".format("Ho", "Hö")
----
Ho



so, what am i doing wrong ?

Answer

Just let python know that you're leading with UTF-8 strings by adding a u in front of the string literal.

print u"----\n{:>4}\n{:>4}".format("Ho", u"Hö")