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


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

Re: Case-insensitive sorting of strings (Python newbie)

Started byChris Angelico <rosuav@gmail.com>
First post2015-01-24 04:58 +1100
Last post2015-01-24 04:58 +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: Case-insensitive sorting of strings (Python newbie) Chris Angelico <rosuav@gmail.com> - 2015-01-24 04:58 +1100

#84373 — Re: Case-insensitive sorting of strings (Python newbie)

FromChris Angelico <rosuav@gmail.com>
Date2015-01-24 04:58 +1100
SubjectRe: Case-insensitive sorting of strings (Python newbie)
Message-ID<mailman.18048.1422035937.18130.python-list@python.org>
On Sat, Jan 24, 2015 at 4:53 AM, Peter Otten <__peter__@web.de> wrote:
> Now the same with unicode. To read text with a specific encoding use either
> codecs.open() or io.open() instead of the built-in (replace utf-8 with your
> actual encoding):
>
>>>> import io
>>>> for line in io.open("tmp.txt", encoding="utf-8"):
> ...     line = line.strip()
> ...     print line, line.lower()

In Python 3, the built-in open() function sports a fancy encoding=
parameter like that.

for line in open("tmp.txt", encoding="utf-8"):

If you can, I would recommend using Python 3 for all this kind of
thing. The difference may not be huge, but there are all sorts of
little differences here and there that mean that Unicode support is
generally better; most of it stems from the fact that the default
quoted string literal is a Unicode string rather than a byte string,
which means that basically every function ever written for Py3 has
been written to be Unicode-compatible.

ChrisA

[toc] | [standalone]


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


csiph-web