stepper_m stepper_m - 1 year ago 135
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ö")

so, what am i doing wrong ?

Answer Source

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ö")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download