You are not logged in.

#1 2006-05-30 21:43:22

Chman
Member
Registered: 2006-01-31
Posts: 169
Website

Python unicode

After some non-concluding searchs on google, I ask for help about something I don't really understand. It's about python and unicode. I'm trying to print some unicode characters in a terminal. Here's an example :

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

print "─├"

Output :

─├

So I tried it this way :

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

print u"─├".encode('utf-8')

And this way :

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

print u"u2500u251c".encode('utf-8')

But I get the same output... Well, I think there's something I don't understand about python's way to handle unicode strings. One thing I know, it's not coming from my terminal because I get the same output in xterm, urxvt and terminal (xfce's one) and I can see those chars in ncurses applications.

Could someone be good enough to tell me what am I doing wrong ?

Thanks.

(looks like arch's bbs don't like unicode strings, if you want to see what kind of characters I'm trying to print, go http://fr.wikipedia.org/wiki/Table_des_ … code/U2500 )

Offline

#2 2006-05-30 21:59:42

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: Python unicode

>>> print u'Hellou0020World'
Hello World

Offline

#3 2006-05-30 22:14:01

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: Python unicode

There can be issues with printing to terminals - often it depends on the supported encoding of the terminal itself. Always check by redirecting output to a file and looking at the unicode text in a text editor. If it's looking as expected, then you can play around with terminal settings, etc.

Offline

Board footer

Powered by FluxBB