>>compile('U"ÖÐ"','c:/test','single')
<code object ? at 00F06B60, file "c:/test", line 1>
>>d=compile('U"ÖÐ"','c:/test','single') d
<code object ? at 00F06BA0, file "c:/test", line 1>
>>exec(d)
u'\xd6\xd0'
>>U"ÖÐ"
u'\u4e2d'
>>>
why is the result different?
a bug or another reason? 4 1310
ygao wrote:
>>>compile('U"ä¸*"','c:/test','single')
<code object ? at 00F06B60, file "c:/test", line 1>
>>>d=compile('U"ä¸*"','c:/test','single') d
<code object ? at 00F06BA0, file "c:/test", line 1>
>>>exec(d)
u'\xd6\xd0'
>>>U"ä¸*"
u'\u4e2d'
>>>>
why is the result different?
a bug or another reason?
How that particular output came to be I don't know, but you should be able
to avoid the confusion by either passing a unicode string to compile() or
specifying the encoding:
>>exec compile(u'u"ä¸*"','c:/test','single')
u'\u4e2d'
>>exec compile('# -*- coding: utf8 -*-\nu"ä¸*"','c:/test','single')
u'\u4e2d'
Peter
PS: In and all-UTF-8 environment I would have /expected/ to see
>>your_encoding = "utf8" identity = "latin1" u'\u4e2d'.encode(your_encoding).decode(identit y)
u'\xe4\xb8\xad'
and that's indeed what I get over here:
>>exec compile('u"ä¸*"','c:/test','single')
u'\xe4\xb8\xad'
Peter Otten wrote:
ygao wrote:
>>compile('U"ä¸*"','c:/test','single')
<code object ? at 00F06B60, file "c:/test", line 1>
>>d=compile('U"ä¸*"','c:/test','single') d
<code object ? at 00F06BA0, file "c:/test", line 1>
>>exec(d)
u'\xd6\xd0'
>>U"ä¸*"
u'\u4e2d'
>>>
why is the result different?
a bug or another reason?
How that particular output came to be I don't know, but you should be able
to avoid the confusion by either passing a unicode string to compile() or
specifying the encoding:
>exec compile(u'u"ä¸*"','c:/test','single')
u'\u4e2d'
>exec compile('# -*- coding: utf8 -*-\nu"ä¸*"','c:/test','single')
u'\u4e2d'
Peter
PS: In and all-UTF-8 environment I would have /expected/ to see
>your_encoding = "utf8" identity = "latin1" u'\u4e2d'.encode(your_encoding).decode(identity )
u'\xe4\xb8\xad'
and that's indeed what I get over here:
>exec compile('u"ä¸*"','c:/test','single')
u'\xe4\xb8\xad'
But it's not an all-UTF-8 environment; his_encoding = 'gb2312' or one
of its heirs/successors :-)
Cheers,
John
John Machin wrote:
But it's not an all-UTF-8 environment; his_encoding = 'gb2312' or one
of its heirs/successors :-)
Ouch. Almost understanding a problem hurts more than not understanding it at
all. I just had a refresher of the experience...
Peter
Peter Otten wrote:
ygao wrote:
>>compile('U"ä¸*"','c:/test','single')
<code object ? at 00F06B60, file "c:/test", line 1>
>>d=compile('U"ä¸*"','c:/test','single') d
<code object ? at 00F06BA0, file "c:/test", line 1>
>>exec(d)
u'\xd6\xd0'
>>U"ä¸*"
u'\u4e2d'
>>>
why is the result different?
a bug or another reason?
How that particular output came to be I don't know, but you should be able
to avoid the confusion by either passing a unicode string to compile() or
specifying the encoding:
>exec compile(u'u"ä¸*"','c:/test','single')
u'\u4e2d'
>exec compile('# -*- coding: utf8 -*-\nu"ä¸*"','c:/test','single')
u'\u4e2d'
this is what I want!
many thanks!
>
Peter
PS: In and all-UTF-8 environment I would have /expected/ to see
>your_encoding = "utf8" identity = "latin1" u'\u4e2d'.encode(your_encoding).decode(identity )
u'\xe4\xb8\xad'
and that's indeed what I get over here:
>exec compile('u"ä¸*"','c:/test','single')
u'\xe4\xb8\xad'
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: xuatla |
last post by:
Hi,
I encountered the following compile error of c++ and hope to get your help.
test2.cpp: In member function `CTest CTest::operator+=(CTest&)':
test2.cpp:79: error: no match for 'operator='...
|
by: Douglas |
last post by:
**** Post for FREE via your newsreader at post.usenet.com ****
Hello,
The following code does not compile if line 3 is uncommented "using
namespace std".
I do not understand it. Could...
|
by: newbiecpp |
last post by:
I have hard time to understand run-time environment. Let assume that I have
a program that has a simple variable alpha. When this variable is
statically allocated, the compiler can use the...
|
by: Jean-David Beyer |
last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2
V6.1 (with all the FixPacks) on my old machine.
I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
|
by: Michael L. Hostbaek |
last post by:
Hi,
I am trying to compile a piece of software, on a FreeBSD system.
gcc version 2.95.4
When compiling, I get lots of these warnings:
---
logger.c: In function `cf_logger_init':
|
by: JS |
last post by:
I use winXP and have installed Cygwin. I use Dev-C++ and the Cygwin
compiler, but for some reason I can't compile this code:
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
...
|
by: Chris LaJoie |
last post by:
Our company has been developing a program in C# for some time now, and we
haven't had any problems with it, but just last night something cropped up
that has me, and everyone else, stumped.
I...
|
by: Frederick Gotham |
last post by:
I don't like macros for a few reasons -- here's just a few...
Reason 1:
namespace ArbitraryNamespace {
#define Func(i) ( i + '0' )
}
|
by: Ioannis Vranos |
last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard,
something simple like defining a function as:
void somefunc(void) throw()
{
// ...
}
|
by: CodeMonk3y |
last post by:
gotta question on sizeof keyword
does the sizeof keyword calcuates the size at compile time or run time ??
-- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
| |