Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83994
| References | <CAGAAoy3kyhwTexNNv3Bs0of=6h2dT6OD5kvZF-PUzauUCociQg@mail.gmail.com> |
|---|---|
| Date | 2015-01-19 05:13 +1100 |
| Subject | Re: Formatting string with accented characters for printing |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17840.1421604837.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Formatting string with accented characters for printing Chris Angelico <rosuav@gmail.com> - 2015-01-19 05:13 +1100
csiph-web