Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: compile(unicode) & source encoding

Reply
Thread Tools

Re: compile(unicode) & source encoding

 
 
Denis S. Otkidach
Guest
Posts: n/a
 
      12-01-2003
On 28 Nov 2003, Martin v. [iso-8859-15] Löwis wrote:

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

Why we have to choose one particular encoding and not just assume
all strings to be unicode?

MvL> In addition, anybody desiring a different encoding can
MvL> explicitly
MvL> invoke .encode()

Surely. But there is no way to emulate "python -U" behavior for
compiled piece of code.

--
Denis S. Otkidach
http://www.python.ru/ [ru]


 
Reply With Quote
 
 
 
 
Martin v. =?iso-8859-15?q?L=F6wis?=
Guest
Posts: n/a
 
      12-01-2003
"Denis S. Otkidach" <> writes:

> Why we have to choose one particular encoding and not just assume
> all strings to be unicode?


Assume the source code reads

source = u"""
f=open("/etc/passwd","a")
f.write("news:9:13:News system:/etc/news:/bin/bash\n")
"""

What data type should the argument of f.write have, in this example?

If the answer is not <type 'str'>, you would cause many compatibility
problems.

> Surely. But there is no way to emulate "python -U" behavior for
> compiled piece of code.


However, python -U does not currently work. When it does, exposing it
separately to compile() might be reasonable. OTOH, the current
behaviour might be sufficient: If -U is passed, strings created in
compile would automatically be Unicode strings - which is the case
today.

Regards,
Martin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Text File Encoding and converting to Perls internal UTF-8 encoding sln@netherlands.com Perl Misc 2 04-17-2009 11:22 PM
changing JVM encoding; setting -Dfile.encoding doesn't work pasmol@plusnet.pl Java 1 10-08-2004 09:50 PM
Encoding.Default and Encoding.UTF8 Hardy Wang ASP .Net 5 06-09-2004 04:04 PM
compile(unicode) & source encoding Denis S. Otkidach Python 2 11-28-2003 09:30 PM
Trouble with source-code encoding Fernando Rodriguez Python 3 09-12-2003 08:16 PM



Advertisments