Re: compile(unicode) & source encoding

Discussion in 'Python' started by Denis S. Otkidach, Dec 1, 2003.

  1. 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]
    Denis S. Otkidach, Dec 1, 2003
    #1
    1. Advertising

  2. "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:x: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
    Martin v. =?iso-8859-15?q?L=F6wis?=, Dec 1, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hardy Wang

    Encoding.Default and Encoding.UTF8

    Hardy Wang, Jun 8, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    18,796
    Jon Skeet [C# MVP]
    Jun 9, 2004
  2. Denis S. Otkidach

    compile(unicode) & source encoding

    Denis S. Otkidach, Nov 28, 2003, in forum: Python
    Replies:
    2
    Views:
    289
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Nov 28, 2003
  3. Replies:
    8
    Views:
    487
  4. Nagaraj
    Replies:
    1
    Views:
    832
    Lionel B
    Mar 1, 2007
  5. fAnSKyer
    Replies:
    2
    Views:
    513
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page