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


Groups > comp.lang.python > #5168

Re: unicode by default

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'context': 0.04; 'wed,': 0.04; '2.7': 0.05; '2.x': 0.05; '3.2': 0.07; 'ascii': 0.07; 'mode,': 0.07; 'width': 0.07; 'python': 0.07; '3.x': 0.09; 'default)': 0.09; 'default.': 0.09; 'internally': 0.09; 'utf-8': 0.09; 'pm,': 0.11; 'programmer': 0.11; 'binary': 0.14; 'wrote:': 0.14; '(utf-16)': 0.16; '.py': 0.16; 'conversions.': 0.16; 'cpython,': 0.16; 'folks,': 0.16; 'installs': 0.16; 'mean,': 0.16; 'output?': 0.16; 'stream.': 0.16; 'subject:unicode': 0.16; 'ucs-4': 0.16; 'what?': 0.16; 'compiled': 0.18; 'bytes': 0.19; 'compile': 0.19; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'trying': 0.23; '\xa0if': 0.23; 'mainly': 0.24; "didn't": 0.25; 'version': 0.25; 'byte': 0.25; 'specify': 0.25; 'used,': 0.25; 'installation': 0.25; 'received:209.85.161.46': 0.26; 'received :mail-fx0-f46.google.com': 0.26; "i'm": 0.26; 'message- id:@mail.gmail.com': 0.28; 'knowing': 0.29; 'received:209.85.161': 0.29; 'problem': 0.29; 'mode': 0.29; 'class': 0.29; 'assuming': 0.29; 'explicitly': 0.29; 'unicode': 0.29; 'books': 0.30; 'points': 0.31; '(just': 0.31; 'confused': 0.31; 'detail.': 0.31; 'unicode,': 0.31; 'does': 0.31; "can't": 0.31; 'to:addr:python- list': 0.32; 'option': 0.33; 'things': 0.33; 'handling': 0.33; 'using': 0.34; 'change': 0.34; 'there': 0.35; 'file': 0.35; 'open': 0.35; 'tool': 0.35; '2.6': 0.35; 'explicit': 0.35; 'stuck': 0.35; 'think': 0.36; 'some': 0.37; 'received:209.85': 0.37; 'either': 0.37; 'run': 0.37; '(by': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'so,': 0.38; 'used': 0.38; 'help': 0.39; 'affect': 0.39; 'errors': 0.39; 'somewhat': 0.39; 'sources': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'comes': 0.39; 'received:209': 0.39; 'how': 0.39; 'header:Received:5': 0.40; 'exact': 0.60; '2011': 0.62; 'conversion': 0.64; 'due': 0.67; 'requiring': 0.69; 'capabilities': 0.72; '11,': 0.77; 'correctly?': 0.84; 'encoding,': 0.84; 'of...': 0.84; 'probably,': 0.84; 'spoiled': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=784Kp68Z3hTmTsLz+DlXtZukmidksgvRG4vE1+Kv1C4=; b=rL9He4wucjWmLeZyyO1aDYDCDJ/G5HEa+Xr3aiTtsgZAg4hPzePl5H0xR37zH7cMHc cxZEjD0eY4V1e1TH7DeKfz7jBigKHrVlrb2tDUHR0y6i2C92wusPozkoZOnKuuiQJ7KI Nk63qMrA9y58k4CaYpumefL+ku7aN0uvEqBN8=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=dATA697NFD8pAoIidurPbRwixf9NCtjhtU8GZMRJ4YNU1a/VmJRq7HIE+xrTfXmSdl 4Ls12gZI+qxJ+mzyMTLhb93g+CZigRMoGMF/+C7w7WQYTIZ+OmPTvtmn/FyPX+80FzwE LuzM0rzOq/ls471WEabdAhFrAQacvszBhxujM=
MIME-Version 1.0
In-Reply-To <OkDyp.2983$M61.450@newsfe07.iad>
References <OkDyp.2983$M61.450@newsfe07.iad>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 11 May 2011 16:09:29 -0600
Subject Re: unicode by default
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1433.1305151801.9059.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 82.94.164.166
X-Trace 1305151801 news.xs4all.nl 41110 [::ffff:82.94.164.166]:40541
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5168

Show key headers only | View raw


On Wed, May 11, 2011 at 3:37 PM, harrismh777 <harrismh777@charter.net> wrote:
> hi folks,
>   I am puzzled by unicode generally, and within the context of python
> specifically. For one thing, what do we mean that unicode is used in python
> 3.x by default. (I know what default means, I mean, what changed?)

The `unicode' class was renamed to `str', and a stripped-down version
of the 2.X `str' class was renamed to `bytes'.

>   I think part of my problem is that I'm spoiled (American, ascii heritage)
> and have been either stuck in ascii knowingly, or UTF-8 without knowing
> (just because the code points lined up). I am confused by the implications
> for using 3.x, because I am reading that there are significant things to be
> aware of... what?

Mainly Python 3 no longer does explicit conversion between bytes and
unicode, requiring the programmer to be explicit about such
conversions.  If you have Python 2 code that is sloppy about this, you
may get some Unicode encode/decode errors when trying to run the same
code in Python 3.  The 2to3 tool can help somewhat with this, but it
can't prevent all problems.

>   On my installation 2.6  sys.maxunicode comes up with 1114111, and my 2.7
> and 3.2 installs come up with 65535 each. So, I am assuming that 2.6 was
> compiled with UCS-4 (UTF-32) option for 4 byte unicode(?) and that the
> default compile option for 2.7 & 3.2 (I didn't change anything) is set for
> UCS-2 (UTF-16) or 2 byte unicode(?).   Do I understand this much correctly?

I think that UCS-2 has always been the default unicode width for
CPython, although the exact representation used internally is an
implementation detail.

>   The books say that the .py sources are UTF-8 by default... and that 3.x is
> either UCS-2 or UCS-4.  If I use the file handling capabilities of Python in
> 3.x (by default) what encoding will be used, and how will that affect the
> output?

If you open a file in binary mode, the result is a non-decoded byte stream.

If you open a file in text mode and do not specify an encoding, then
the result of locale.getpreferredencoding() is used for decoding, and
the result is a unicode stream.

>   If I do not specify any code points above ascii 0xFF does any of this
> matter anyway?

You mean 0x7F, and probably, due to the need to explicitly encode and decode.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-11 16:37 -0500
  Re: unicode by default Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-11 16:09 -0600
    Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-11 17:51 -0500
      Re: unicode by default "John Machin" <sjmachin@lexicon.net> - 2011-05-12 09:32 +1000
        Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-11 20:22 -0500
          Re: unicode by default MRAB <python@mrabarnett.plus.com> - 2011-05-12 03:31 +0100
            Re: unicode by default Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-12 03:16 +0000
              Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-11 22:44 -0500
                Re: unicode by default Terry Reedy <tjreedy@udel.edu> - 2011-05-12 00:12 -0400
                Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-12 01:43 -0500
                Re: unicode by default "John Machin" <sjmachin@lexicon.net> - 2011-05-12 14:14 +1000
                Re: unicode by default Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-05-11 21:14 -0700
                Re: unicode by default "John Machin" <sjmachin@lexicon.net> - 2011-05-12 14:41 +1000
                Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-12 01:14 -0500
                Re: unicode by default TheSaint <nobody@nowhere.net.no> - 2011-05-12 20:40 +0800
            Re: unicode by default Ben Finney <ben+python@benfinney.id.au> - 2011-05-12 14:07 +1000
              Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-12 01:31 -0500
                Re: unicode by default "John Machin" <sjmachin@lexicon.net> - 2011-05-12 17:58 +1000
                Re: unicode by default Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-12 10:17 -0600
                Re: unicode by default jmfauth <wxjmfauth@gmail.com> - 2011-05-12 23:28 -0700
                Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-13 14:53 -0500
                Re: unicode by default Robert Kern <robert.kern@gmail.com> - 2011-05-13 15:18 -0500
                Re: unicode by default Terry Reedy <tjreedy@udel.edu> - 2011-05-13 21:41 -0400
                Re: unicode by default harrismh777 <harrismh777@charter.net> - 2011-05-14 02:41 -0500
                Re: unicode by default jmfauth <wxjmfauth@gmail.com> - 2011-05-14 03:26 -0700
                Re: unicode by default Terry Reedy <tjreedy@udel.edu> - 2011-05-14 16:26 -0400
                Re: unicode by default Ben Finney <ben+python@benfinney.id.au> - 2011-05-15 09:47 +1000
                Re: unicode by default Nobody <nobody@nowhere.com> - 2011-05-14 09:34 +0100
                Re: unicode by default Terry Reedy <tjreedy@udel.edu> - 2011-05-12 16:42 -0400
                Re: unicode by default Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-12 16:25 -0600
          Re: unicode by default "John Machin" <sjmachin@lexicon.net> - 2011-05-12 13:54 +1000
  Re: unicode by default Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-05-11 15:34 -0700

csiph-web