473,395 Members | 2,222 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,395 software developers and data experts.

compile(unicode) & source encoding


I have 2 questions about compile

1. What is the reason to encode source code to utf-8? I guess
"python -U" behavior is the best choice in this case. The
following snippet seems to fix this, but I'm not sure it's
correct in all cases:

for const in code.co_consts:
if type(const) is str:
consts.append(const.decode('utf-8'))
else:
consts.append(const)
import new
code = new.code(code.co_argcount, code.co_nlocals,
code.co_stacksize, code.co_flags, code.co_code,
tuple(consts), code.co_names, code.co_varnames,
code.co_filename, code.co_name,
code.co_firstlineno, code.co_lnotab)
return code
2. Why there is now option to define encoding of source passed to
compile function? Yes, I can define encoding by prefixing my
code with '# -*- coding: %s -*-\n' % encoding, but it's not
handy.

--
Denis S. Otkidach
http://www.python.ru/ [ru]
Jul 18 '05 #1
2 2148
In article <ma*************************************@python.or g>,
"Denis S. Otkidach" <od*@strana.ru> wrote:
2. Why there is now option to define encoding of source passed to
compile function? Yes, I can define encoding by prefixing my
code with '# -*- coding: %s -*-\n' % encoding, but it's not
handy.


You can just pass a unicode string (in 2.3 at least), so you can do the
decoding yourself.

Just
Jul 18 '05 #2
"Denis S. Otkidach" <od*@strana.ru> writes:

[In the context of compile()]
1. What is the reason to encode source code to utf-8?
I think it is because Just found that the most straight-forward thing
to do: UTF-8 supports all Unicode characters, and you have to choose
*some* encoding, as the resulting byte strings need to be encoded
somehow.

In addition, anybody desiring a different encoding can explicitly
invoke .encode()
2. Why there is now option to define encoding of source passed to
compile function?


No, although this should be implemented. It is not implemented at this
point because it is very hard to do, and I have not found a good way
to do it, yet.

Regards,
Martin
Jul 18 '05 #3

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

Similar topics

8
by: Bill Eldridge | last post by:
I'm trying to grab a document off the Web and toss it into a MySQL database, but I keep running into the various encoding problems with Unicode (that aren't a problem for me with GB2312, BIG 5,...
8
by: janeaustine50 | last post by:
Python's InteractiveInterpreter uses the built-in compile function. According to the ref. manual, it doesn't seem to concern about the encoding of the source string. When I hand in an unicode...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
1
by: Keith Clark | last post by:
When I load a csharp program into the MS DbgCLR.exe debugger and trace it everything is fine the first time. Assume now, I change somewhere a code statement in the source file (outside the...
1
by: M.Komeily | last post by:
i want to set farsi text in static control or button. but VC++ .NET resource editor cant permit. whereas VC# and VB can. how can i solving this problem. sincerely m.komeily
4
by: needin4mation | last post by:
I work in Visual Studio, but not everyone where I am at does. Sometimes, however, they may have to make minor adjustments here and there. Since the code is c#, behindform code, if they make an...
6
by: Martin Horn | last post by:
Hi, I have encountered a problem with compiling my project. Basically what happened was that I noticed my PC date was set a day into the future, so I reset it to the correct date. Now when I...
2
by: andreister | last post by:
Hi skilled, I wonder if anybody knows how the ASP.NET actually does this. So far I have been assuming the following: 1. aspx pages are compiled in gory-named files (ken0-m7f.0.jsl or something)...
3
by: singhPrabhat | last post by:
I want to compile source files which is in different directory than Makefile. How can I do this? GCC=gcc DEFs=-DCUSTOMERCENTRAL_V11 -DUNIX -DLINUX -DOPENSSL -D_REENTRANT CCWebConfiguration.o:...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.