[TxMt] Python unicode error (was: r8839 (Python)) [reposting]

Hans-Joerg Bibiko bibiko at eva.mpg.de
Mon Jun 2 13:29:25 UTC 2008


On 2 Jun 2008, at 15:17, Alexey Blinov wrote:

> Hmm... little test give me that:
> ------------------------------------
> nilcolor$ cat test.py
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> import sys
> import os
>
> a = u"æble"
> sys.__stdout__.write( a.encode("raw_unicode_escape") + "\n" )
> print a
> nilcolor$ python test.py
> ?ble
> æble
> nilcolor$
> -------------------------------------
> so... IMO print is better. Isn't it?
>

I forgot to mention that I used PyMate for it. If I open that python  
in TM and press APPLE+R I got this:

______
PyMate r8839 running Python 2.4.2 (/usr/bin/env python)
 >>> untitled

æble
æble
Program exited.
_______


If you want to use that script from the command line, please try this  
one:

_______
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os

a = u"æble"
sys.__stdout__.write( a.encode("raw_unicode_escape") + "\n" )
print a.encode("raw_unicode_escape")

________

 >  python foo.py > out.txt
 >  mate out.txt

and you will see in both cases that it works.

Cheers,

--Hans




More information about the textmate mailing list