Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83994 > unrolled thread

Re: Formatting string with accented characters for printing

Started byChris Angelico <rosuav@gmail.com>
First post2015-01-19 05:13 +1100
Last post2015-01-19 05:13 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Formatting string with accented characters for printing Chris Angelico <rosuav@gmail.com> - 2015-01-19 05:13 +1100

#83994 — Re: Formatting string with accented characters for printing

FromChris Angelico <rosuav@gmail.com>
Date2015-01-19 05:13 +1100
SubjectRe: Formatting string with accented characters for printing
Message-ID<mailman.17840.1421604837.18130.python-list@python.org>
On Mon, Jan 19, 2015 at 3:04 AM, Jerry Rocteur <jerry.rocteur@gmail.com> wrote:
>
> I've tried both:
>
>     print '{0:2} {1:25} {2} '.format( cnt, nam[num].encode('utf-8'),
> steps[ind1])
>     print "%3d %-25s %-7s" % ( cnt, nam[num].encode('utf-8'), steps[ind1])
>
> I've searched but I can't see a solution..
>
> I guess it is the way I'm printing nam[num].encode('utf-8') perhaps I
> have to convert it first ?

Do the formatting on a Unicode string, and then encode the entire
string at the end. Or, better still, just work entirely with Unicode
all the way; if you switch to Python 3.4 (or anything else in the 3.x
line), print() takes Unicode strings. This kind of thing becomes easy.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web