473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1369
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 --
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.