Anyway to designating the encoding of the "source" for compile?

janeaustine50 at hotmail.com janeaustine50 at hotmail.com
Tue May 17 02:28:40 EDT 2005


John Machin wrote:
> On 16 May 2005 16:44:30 -0700, janeaustine50 at hotmail.com wrote:
[snip]
>
>
> Like I said, *ALL* you have to do (like in any other Unicode-aware
> app) is decode your user input into Unicode (you *don't* need to
parse
> bits and pieces of it) and feed it in ... like this:
>
> >>> user_input_kr = "inside=u'\xc7\xd1\xb1\xdb'"
> >>> user_input_uc = user_input_kr.decode('euc-kr')
> >>> user_input_uc
> u"inside=u'\ud55c\uae00'"
> >>> s = compile(user_input_uc, '', 'single')
> >>> exec s
> >>> inside
> u'\ud55c\uae00'
> >>> # right
>
> HTH,
> John

Thank you but there is still a problem.

|>>> s='euckr="\xc7\xd1";uni=u"\xc7\xd1"'
|>>> su=s.decode('euc-kr')
|>>> su
|u'euckr="\ud55c";uni=u"\ud55c"'
|>>> c=compile(su,'','single')
|>>> exec c
|>>> euckr,uni
|('\xed\x95\x9c', u'\ud55c')
|>>>

As you see the single's result is turned into UTF-8 encoding.




More information about the Python-list mailing list