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: 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: References: From: Ian Kelly Date: Wed, 11 May 2011 16:09:29 -0600 Subject: Re: unicode by default To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, May 11, 2011 at 3:37 PM, harrismh777 wrot= e: > hi folks, > =A0 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 pyth= on > 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'. > =A0 I think part of my problem is that I'm spoiled (American, ascii herit= age) > 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 implication= s > 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. > =A0 On my installation 2.6 =A0sys.maxunicode comes up with 1114111, and m= y 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 fo= r > UCS-2 (UTF-16) or 2 byte unicode(?). =A0 Do I understand this much correc= tly? I think that UCS-2 has always been the default unicode width for CPython, although the exact representation used internally is an implementation detail. > =A0 The books say that the .py sources are UTF-8 by default... and that 3= .x is > either UCS-2 or UCS-4. =A0If I use the file handling capabilities of Pyth= on 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. > =A0 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 decod= e.