Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94362
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; 'subject:Python': 0.05; '-*-': 0.07; 'constructor': 0.07; 'utf-8': 0.07; 'cc:addr:python-list': 0.09; '22,': 0.09; 'coding:': 0.09; 'literal': 0.09; 'subject:string': 0.09; 'wed,': 0.15; 'encoding': 0.15; 'anatoly': 0.16; 'decode': 0.16; 'file?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.16; 'string': 0.17; 'string,': 0.18; 'library': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'so.': 0.22; 'parser': 0.22; 'defined': 0.23; 'import': 0.24; 'header:In- Reply-To:1': 0.24; "doesn't": 0.26; 'entered': 0.27; 'message- id:@mail.gmail.com': 0.27; 'declared': 0.29; 'entry': 0.31; 'source': 0.33; 'point,': 0.33; 'received:google.com': 0.35; 'unicode': 0.35; 'there': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:e 20': 0.39; 'your': 0.60; 'matter': 0.63; '8bit%:50': 0.66; 'jul': 0.72; 'chrisa': 0.84; 'seen.': 0.84; 'source:': 0.84; 'to:none': 0.91 |
| 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:content-transfer-encoding; bh=jora1+INzyLLSDGsvua3x7Vc8jHIhfvSW6r8Gitlf1s=; b=VZJj5pkK/fOabn8WSbnnq2XfHf3CU+DwNFAlmPQHRQT9uwiR80FgvTU188h9afcBsw i+4Q1ViXnLjfwFaSQt1r6TWsqcZFEaTBh9OkGsDnX+CFuhzRiFgn3yT5GAhnG7yWjruz wELFDQg9WcrdINXeUe+6dDF4fv+xiZv24N3CIEo/7uK3K8L5drI0RPJQ/vhbsrSdMKbw wVtE1d5PyoBjCMlFBzEJNxIZ9pFJBqRi+VSeqxT4gB1qDP5WNG3Zkpso18jCNOx68VAG c9sm3k2+esr4B9b/FcNXTZMYKDU31p+h4AC5wX2TCz7KzoxS4sVkKevzTRj8vx+Sab8w OzZw== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.4.1 with SMTP id 1mr3971428ioe.10.1437568796812; Wed, 22 Jul 2015 05:39:56 -0700 (PDT) |
| In-Reply-To | <CAPkN8xK674+ruL=2gU9xHsuDAY0H3D_CBux8mY78ZYzo55gdHw@mail.gmail.com> |
| References | <CAPkN8xK674+ruL=2gU9xHsuDAY0H3D_CBux8mY78ZYzo55gdHw@mail.gmail.com> |
| Date | Wed, 22 Jul 2015 22:39:56 +1000 |
| Subject | Re: Encoding of Python 2 string literals |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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.865.1437568800.3674.python-list@python.org> (permalink) |
| Lines | 22 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1437568800 news.xs4all.nl 2878 [2001:888:2000:d::a6]:40395 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:94362 |
Show key headers only | View raw
On Wed, Jul 22, 2015 at 8:17 PM, anatoly techtonik <techtonik@gmail.com> wrote:
> Is there a way to know encoding of string (bytes) literal
> defined in source file? For example, given that source:
>
> # -*- coding: utf-8 -*-
> from library import Entry
> Entry("текст")
>
> Is there any way for Entry() constructor to know that
> string "текст" passed into it is the utf-8 string?
I don't think so. However, if you declare that to be a Unicode string,
the parser will decode it using the declared encoding, and it'll be a
five-character string. At that point, it doesn't matter what your
source encoding was, because the characters entered will match the
characters seen.
Entry(u"текст")
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Encoding of Python 2 string literals Chris Angelico <rosuav@gmail.com> - 2015-07-22 22:39 +1000
csiph-web