472,354 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

can compile function have a bug?

>>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?

Oct 8 '06 #1
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'
Oct 9 '06 #2

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

Oct 9 '06 #3
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
Oct 9 '06 #4

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'
Oct 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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='...
8
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...
17
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...
10
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...
8
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':
12
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> ...
10
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...
2
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' ) }
12
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() { // ... }
27
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 --
2
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...
0
jalbright99669
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...
0
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...
2
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...
0
hi
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...
0
Oralloy
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++...
0
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...
0
BLUEPANDA
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.