Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83992 > unrolled thread
| Started by | Jerry Rocteur <jerry.rocteur@gmail.com> |
|---|---|
| First post | 2015-01-18 17:04 +0100 |
| Last post | 2015-01-27 11:16 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Formatting string with accented characters for printing Jerry Rocteur <jerry.rocteur@gmail.com> - 2015-01-18 17:04 +0100
Re: Formatting string with accented characters for printing John Ladasky <john_ladasky@sbcglobal.net> - 2015-01-27 11:16 -0800
| From | Jerry Rocteur <jerry.rocteur@gmail.com> |
|---|---|
| Date | 2015-01-18 17:04 +0100 |
| Subject | Formatting string with accented characters for printing |
| Message-ID | <mailman.17838.1421604508.18130.python-list@python.org> |
Hi,
When I try and format output when there are accented characters the
output does not look right.
e.g.
27 Angie Dickons 67,638
28 Anne MÉRESSE 64,825
So the strings containing accented characters print one less than
those that don't.
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 ?
Can someone please help.
Thanks
--
Jerry Rocteur
Jerry@rocteur.com
[toc] | [next] | [standalone]
| From | John Ladasky <john_ladasky@sbcglobal.net> |
|---|---|
| Date | 2015-01-27 11:16 -0800 |
| Message-ID | <bace8bc5-c8af-4d9a-b43e-c78044560dd7@googlegroups.com> |
| In reply to | #83992 |
Jerry, I can tell from your code that you are using Python 2. If you are a new Python programmer, and you do not HAVE to use Python 2, use Python 3 instead. In Python 3, text objects are something called "Unicode" rather than just sequences of bytes. Unicode makes it much easier to handle characters which are not part of the English alphabet.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web