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


Groups > comp.lang.python > #66128

Re: Wait... WHAT?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'encoding': 0.05; 'encode': 0.09; 'hiding': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; "'w')": 0.16; "'w',": 0.16; 'codec': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hides': 0.16; 'open()': 0.16; 'ordinal': 0.16; 'prevent': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'thu,': 0.19; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'unicode': 0.24; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'tim': 0.29; "doesn't": 0.30; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; '"",': 0.31; '13,': 0.31; '>>>>': 0.31; 'chase': 0.31; 'file': 0.32; 'linux': 0.33; '(most': 0.33; "can't": 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'should': 0.36; 'lists.': 0.38; 'recent': 0.39; 'though,': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'is.': 0.60; 'skip:c 50': 0.60; 'more': 0.64; 'default': 0.69; '11:44': 0.84; '2014,': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=2ZMqt5xMb4g3YDEXsj/+MNBPNaOUf8yNXS93KWKM2FI=; b=Qwpo1OaKeeNzfYaYupteAHB7Y2a9EHSi01dFqa1SgcOhdL7XSiSfILQsljXuJ4lEyf KGlmBzHX1TNAKeVo/8vZGhintTuJzgZiZhepgUPm6viFNtkejy+zgfYKtLtvixoY+tG3 g4+0Pt+FbuYZIEbLnRneT469DzKEkD+s0uU54LbAjX2pPLdIOU9Pyde3bDxnDsYr/sqo Kv+9tCQkk5k3RCAf/e8gpHp4lNCvUOR3NcBCDpNvhzyBMeLXb+zwn0lbuXeKhbO4njjl ibVefZF3GLw6DdtyniPKZSzZVjZ2u0qIsEeCwrpRRmT89ArC7cA9YZRQk6pIlGEMEVh9 kqJg==
MIME-Version 1.0
X-Received by 10.66.129.133 with SMTP id nw5mr42463618pab.98.1392253823043; Wed, 12 Feb 2014 17:10:23 -0800 (PST)
In-Reply-To <20140212184432.1df9b491@bigbox.christie.dr>
References <6c76ef4e-8c7c-4199-b30d-c4d55c1061c8@googlegroups.com> <f45edd72-f8c2-4a20-a1f8-47a1814dfaba@googlegroups.com> <CALwzidnFDxRPmJRXjL2idtqYoccGKaqpACbWGTAyFQDz6juWsQ@mail.gmail.com> <20140212161427.0a9843d5@bigbox.christie.dr> <ldh0hj$nlj$1@ger.gmane.org> <20140212184432.1df9b491@bigbox.christie.dr>
Date Thu, 13 Feb 2014 12:10:22 +1100
Subject Re: Wait... WHAT?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6813.1392253826.18130.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392253826 news.xs4all.nl 2891 [2001:888:2000:d::a6]:60426
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66128

Show key headers only | View raw


On Thu, Feb 13, 2014 at 11:44 AM, Tim Chase
<python.list@tim.thechases.com> wrote:
> Yep:
>
>>>> s = "\u3141" # HANGUL LETTER MIEUM
>>>> f = open('test.txt', 'w')
>>>> f.write("\u3141")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> UnicodeEncodeError: 'ascii' codec can't encode character '\u3141' in
> position 0: ordinal not in range(128)
>
> Just because the open() call hides the specification of how Python
> should do that encoding doesn't prevent the required encoding from
> happening. :-)
>

All it's hiding is what the default encoding is.

Python 3.4.0rc1+ (default:2ba583191550, Feb 12 2014, 10:30:57)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('test.txt', 'w')
>>> f.write("\u3141")
1

Python 3.4.0b2 (v3.4.0b2:ba32913eb13e, Jan  5 2014, 16:23:43) [MSC
v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> f = open('test.txt', 'w')
>>> f.write("\u3141")
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    f.write("\u3141")
  File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u3141' in
position 0: character maps to <undefined>
>>> f = open('test.txt', 'w', encoding='utf-8')
>>> f.write("\u3141")
1

Be explicit, and you can store Unicode strings reliably. That said,
though, you still can't store lists.

ChrisA

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


Thread

Wait... WHAT? eneskristo@gmail.com - 2014-02-12 11:43 -0800
  Re: Wait... WHAT? Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-12 13:13 -0700
  Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-12 12:21 -0800
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 20:38 +0000
    Re: Wait... WHAT? Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-12 14:35 -0700
    Re: Wait... WHAT? Michael Torrie <torriem@gmail.com> - 2014-02-12 14:39 -0700
    Re: Wait... WHAT? Tim Chase <python.list@tim.thechases.com> - 2014-02-12 16:14 -0600
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 23:36 +0000
    Re: Wait... WHAT? Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-12 17:01 -0700
    Re: Wait... WHAT? Tim Chase <python.list@tim.thechases.com> - 2014-02-12 18:44 -0600
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-13 00:59 +0000
    Re: Wait... WHAT? Chris Angelico <rosuav@gmail.com> - 2014-02-13 12:10 +1100
    Re: Wait... WHAT? Tim Chase <python.list@tim.thechases.com> - 2014-02-12 21:29 -0600
    Re: Wait... WHAT? Chris Angelico <rosuav@gmail.com> - 2014-02-13 14:47 +1100
      Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-13 09:46 -0800
        Re: Wait... WHAT? MRAB <python@mrabarnett.plus.com> - 2014-02-13 18:25 +0000
        Re: Wait... WHAT? Michael Torrie <torriem@gmail.com> - 2014-02-13 15:22 -0700
  Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-12 12:43 -0800
    Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 20:56 +0000
      Re: Wait... WHAT? eneskristo@gmail.com - 2014-02-12 12:59 -0800
        Re: Wait... WHAT? Chris Angelico <rosuav@gmail.com> - 2014-02-13 08:17 +1100
        Re: Wait... WHAT? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-12 21:23 +0000
    Re: Wait... WHAT? Grant Edwards <invalid@invalid.invalid> - 2014-02-12 23:09 +0000

csiph-web