nonascii symbols

T

Troels Therkelsen

What's the trick for using nonascii symbols in string literals?

Here's one way of doing it:

Python 2.4a1 (#1, Jul 9 2004, 21:24:13)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Or, in other words, use backslash+x+hexadecimal number representing the byte
value of the symbol you wish to use. Be aware that exactly which symbol
appears when printed depends on the character encoding of your terminal.

For all the ways of doing this see:

http://www.python.org/dev/doc/devel/ref/strings.html

Best regards,

Troels Therkelsen
 
J

John Roth

Troels Therkelsen said:
What's the trick for using nonascii symbols in string literals?

Here's one way of doing it:

Python 2.4a1 (#1, Jul 9 2004, 21:24:13)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Or, in other words, use backslash+x+hexadecimal number representing the byte
value of the symbol you wish to use. Be aware that exactly which symbol
appears when printed depends on the character encoding of your terminal.

Actually, it's supposed to depend on the character encoding comment
at the front of your program. (The default for 2.3 is supposed to be Latin1.
It was supposed to be Ascii for 2.4, but I haven't seen that in the 2.4a1
changes.)

Whether your editor understands this is a different issue.

John Roth
 
R

Ricardo Bugalho

What's the trick for using nonascii symbols in string literals?

Declare the file encoding in the 1st or second line do the file, like
this:

# -*- coding: utf-8 -*-
# Hello world, in portuguese.
print "Olá Mundo!"

However, this doesn't solve the problem of code portability over systems
with different chartsets.
To do that, I like using unicode string literals and locale.

# -*- coding: utf-8 -*-
import locale
country, coding = locale.getdefaultlocale()
str = u'Olá Mundo!'
print str.encode(coding)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,661
Latest member
sxarexu

Latest Threads

Top