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


Groups > comp.lang.python > #94362 > unrolled thread

Re: Encoding of Python 2 string literals

Started byChris Angelico <rosuav@gmail.com>
First post2015-07-22 22:39 +1000
Last post2015-07-22 22:39 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Encoding of Python 2 string literals Chris Angelico <rosuav@gmail.com> - 2015-07-22 22:39 +1000

#94362 — Re: Encoding of Python 2 string literals

FromChris Angelico <rosuav@gmail.com>
Date2015-07-22 22:39 +1000
SubjectRe: Encoding of Python 2 string literals
Message-ID<mailman.865.1437568800.3674.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web