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: 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: References: From: Benjamin Kaplan 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" 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sat, Aug 24, 2013 at 9:47 AM, David M. Cotter wrote: > > > What _are_ you using? > i have scripts in a file, that i am invoking into my embedded python with= in a C++ program. there is no terminal involved. the "print" statement ha= s 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 =3D > "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 =3D CustomPrintClass()\n" > "sys.stderr =3D CustomErrClass()\n" > "sys.stdout.encoding =3D 'UTF-8'\n" > "sys.stderr.encoding =3D '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 origin= al, correct string. who is specifying macRoman, and where, and how do i te= ll 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.