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


Groups > comp.lang.python > #94427

Re: Encoding of Python 2 string literals

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
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; 'subject:Python': 0.05; '-*-': 0.07; 'constructor': 0.07; 'utf-8': 0.07; 'coding:': 0.09; 'literal': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'says.': 0.09; 'subject:string': 0.09; 'wed,': 0.15; 'encoding': 0.15; 'anatoly': 0.16; 'file?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'string:': 0.16; 'wrote:': 0.16; 'string': 0.17; 'library': 0.20; '2015': 0.20; 'parsing': 0.22; 'defined': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'actual': 0.28; 'cookie': 0.29; 'entry': 0.31; 'source': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'file': 0.34; 'saved': 0.35; 'unicode': 0.35; 'there': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'sure': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'easy': 0.60; 'received:217': 0.66; 'jul': 0.72; 'charset:iso-8859-5': 0.84; 'source:': 0.84; '8bit%:33': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From dieter <dieter@handshake.de>
Subject Re: Encoding of Python 2 string literals
Date Thu, 23 Jul 2015 07:58:35 +0200
References <mailman.864.1437567640.3674.python-list@python.org> <55afaad8$0$1646$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=iso-8859-5
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host pd9e09b1d.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:QgPF2fiY4eTgy2u9WGJRVvWBnYA=
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.900.1437631206.3674.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1437631206 news.xs4all.nl 2944 [2001:888:2000:d::a6]:37989
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:94427

Show key headers only | View raw


Steven D'Aprano <steve@pearwood.info> writes:
> On Wed, 22 Jul 2015 08:17 pm, anatoly techtonik 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?
> ...
> The right way to deal with this is to use an actual Unicode string:
>
> Entry(u"текст")
>
> and make sure that the file is saved using UTF-8, as the encoding cookie
> says.

In order to follow this recommendation, is there an easy way to
learn about the "encoding cookie"'s value -- rather than parsing
the first two lines of the source file (which may not always be available).

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


Thread

Re: Encoding of Python 2 string literals Steven D'Aprano <steve@pearwood.info> - 2015-07-23 00:38 +1000
  Re: Encoding of Python 2 string literals Chris Angelico <rosuav@gmail.com> - 2015-07-23 00:54 +1000
  Re: Encoding of Python 2 string literals dieter <dieter@handshake.de> - 2015-07-23 07:58 +0200
  Re: Encoding of Python 2 string literals Chris Angelico <rosuav@gmail.com> - 2015-07-23 16:13 +1000

csiph-web