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


Groups > comp.lang.python > #52947

Re: can't get utf8 / unicode strings from embedded python

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <bsk16@case.edu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; 'static': 0.04; 'string.': 0.05; 'class,': 0.07; 'redirected': 0.07; 'utf-8': 0.07; 'string': 0.09; 'assuming': 0.09; 'bytes.': 0.09; 'converted': 0.09; 'interpreted': 0.09; 'properly.': 0.09; 'python': 0.11; 'def': 0.12; '"."': 0.16; "(it's": 0.16; '(via': 0.16; '24,': 0.16; 'invoking': 0.16; 'specifying': 0.16; 'subject:unicode': 0.16; 'subject:python': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'help.': 0.21; 'aug': 0.22; 'putting': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; "aren't": 0.24; 'bytes': 0.24; 'char': 0.24; 'specify': 0.24; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'correct': 0.29; 'am,': 0.29; 'characters': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'program,': 0.31; 'getting': 0.31; "they'll": 0.31; 'file': 0.32; 'front': 0.32; 'text': 0.33; 'open': 0.33; 'running': 0.33; 'subject:from': 0.34; 'received:209.85': 0.35; 'editor': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'c++': 0.36; "didn't": 0.36; 'shows': 0.36; 'wrong': 0.37; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'embedded': 0.39; 'subject:can': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'subject: / ': 0.60; 'tell': 0.60; 'identify': 0.61; 'skip:* 10': 0.61; "you're": 0.61; 'back': 0.62; 'within': 0.65; 'subject:get': 0.81; '*really*': 0.84; 'const': 0.84; 'received:209.85.214.181': 0.84; 'received :mail-ob0-f181.google.com': 0.84; 'involved.': 0.91; '2013': 0.98
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=AahWz7gkRrrt95GgNqSGUCg6gdLD2QaEWsCM3vsrB0k=; b=gXSthI+a/WXtIdJhc9bIJWvALX8TW8u4fDutkmTSMBe+wVq1OA/HdM19LTTy7VRLI7 SkhzfFUsPh0pIlA7GInxOSH6isbtkJldadeWrVR80reqCdl/kOQbnnYbZ4k6PWj2OLtT g2oECo6YsUgaDt8YdrIwSVTeYL0xXR4L5xjfv8pumjzyMXXfLZYOGGD/uJ4gSQR99JPa YA7Ny5lt9FRNz9gHZnfBzzelqwWVCdFmsnHX+l6lQPcd3TasimyJjsPhePKGk5hxKUP1 jlhF5azLAQwdVAdvhGBjgSUvP5oGx/NntJ9bUyzoIBhHWPWyb8VNwiBk35wMnNRLkZ6U 0k7w==
X-Gm-Message-State ALoCoQkbU3bbh31r24cMPjZHNuv0hSlB7YXDPlifwy3UsgQjiPAC72wr82srGq2NqNn8uOzgJvTuUve57k8n9wnG1Dp7iaQ5hbhG3XVzjVrEEXqgjljVYE9RwAm+SD3P+QGReNTH/VTVuRdGp7lPIMQPF8lkHYMHgw==
X-Received by 10.182.45.195 with SMTP id p3mr5938876obm.29.1377373557708; Sat, 24 Aug 2013 12:45:57 -0700 (PDT)
X-Received by 10.182.45.195 with SMTP id p3mr5938868obm.29.1377373557602; Sat, 24 Aug 2013 12:45:57 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <d3e52d5b-84c9-4cb4-84bf-cbdd886425b1@googlegroups.com>
References <fbeee40a-bc8a-4cef-abe7-2b2d54f59625@googlegroups.com> <d3e52d5b-84c9-4cb4-84bf-cbdd886425b1@googlegroups.com>
From Benjamin Kaplan <benjamin.kaplan@case.edu>
Date Sat, 24 Aug 2013 12:45:37 -0700
Subject Re: can't get utf8 / unicode strings from embedded python
To "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Junkmail-Whitelist YES (by domain whitelist at mpv1.tis.cwru.edu)
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.200.1377373941.19984.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377373941 news.xs4all.nl 15985 [2001:888:2000:d::a6]:39925
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52947

Show key headers only | View raw


On Sat, Aug 24, 2013 at 9:47 AM, David M. Cotter <me@davecotter.com> wrote:
>
> > What _are_ you using?
> i have scripts in a file, that i am invoking into my embedded python within a C++ program.  there is no terminal involved.  the "print" statement has been redirected (via sys.stdout) to my custom print class, which does not specify "encoding", so i tried the suggestion above to set it:
>
> static const char *s_RedirectScript =
>         "import " kEmbeddedModuleName "\n"
>         "import sys\n"
>         "\n"
>         "class CustomPrintClass:\n"
>         "       def write(self, stuff):\n"
>         "               " kEmbeddedModuleName "." kCustomPrint "(stuff)\n"
>         "class CustomErrClass:\n"
>         "       def write(self, stuff):\n"
>         "               " kEmbeddedModuleName "." kCustomErr "(stuff)\n"
>         "sys.stdout = CustomPrintClass()\n"
>         "sys.stderr = CustomErrClass()\n"
>         "sys.stdout.encoding = 'UTF-8'\n"
>         "sys.stderr.encoding = 'UTF-8'\n";
>
>
> but it didn't help.
>
> I'm still getting back a string that is a utf-8 string of characters that, if converted to "macRoman" and then interpreted as UTF8, shows the original, correct string.  who is specifying macRoman, and where, and how do i tell whoever that is that i really *really* want utf8?
> --

If you're running this from a C++ program, then you aren't getting
back characters. You're getting back bytes. If you treat them as
UTF-8, they'll work properly. The only thing wrong is the text editor
you're using to open the file afterwards- since you aren't specifying
an encoding, it's assuming MacRoman. You can try putting the UTF-8 BOM
(it's not really a BOM) at the front of the file- the bytes 0xEF 0xBB
0xBF are used by some editors to identify a file as UTF-8.

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


Thread

can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-23 13:49 -0700
  Re: can't get utf8 / unicode strings from embedded python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-24 01:54 +0000
  Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-23 23:45 -0700
    Re: can't get utf8 / unicode strings from embedded python Dave Angel <davea@davea.name> - 2013-08-24 07:04 +0000
    Re: can't get utf8 / unicode strings from embedded python random832@fastmail.us - 2013-08-24 09:49 -0400
  Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-24 09:47 -0700
    Re: can't get utf8 / unicode strings from embedded python wxjmfauth@gmail.com - 2013-08-24 11:31 -0700
    Re: can't get utf8 / unicode strings from embedded python Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-08-24 12:45 -0700
    Re: can't get utf8 / unicode strings from embedded python random832@fastmail.us - 2013-08-24 20:01 -0400
  Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-25 10:57 -0700
    Re: can't get utf8 / unicode strings from embedded python Vlastimil Brom <vlastimil.brom@gmail.com> - 2013-08-25 20:23 +0200
    Re: can't get utf8 / unicode strings from embedded python Terry Reedy <tjreedy@udel.edu> - 2013-08-25 14:59 -0400
  Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-25 15:25 -0700
  Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-25 15:32 -0700
    Re: can't get utf8 / unicode strings from embedded python MRAB <python@mrabarnett.plus.com> - 2013-08-26 01:30 +0100
      Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-27 15:21 -0700
        Re: can't get utf8 / unicode strings from embedded python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-27 23:24 +0000
          Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-27 22:57 -0700
            Re: can't get utf8 / unicode strings from embedded python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-28 12:03 +0000
  Re: can't get utf8 / unicode strings from embedded python "David M. Cotter" <me@davecotter.com> - 2013-08-28 10:46 -0700

csiph-web