about coding

C

cantabile

Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-'
directive.

I'm using an accented characters language. Some of them are correctly
displayed while one doesn't. I've written :
-*- coding: utf-8 -*-

Is this wrong ?

Where can I find a pratical explanation about these encodings ?

Thanks.
 
R

Robert Kern

cantabile said:
Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-'
directive.

I'm using an accented characters language. Some of them are correctly
displayed while one doesn't. I've written :
-*- coding: utf-8 -*-

Is this wrong ?

It depends. Are those characters encoded as UTF-8? Or, more likely, are
they encoded as ISO-8859-1?
Where can I find a pratical explanation about these encodings ?

http://www.amk.ca/python/howto/unicode
http://en.wikipedia.org/wiki/Character_encoding
http://www.joelonsoftware.com/articles/Unicode.html

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
B

Benjamin Niemann

cantabile said:
Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-'
directive.

I'm using an accented characters language. Some of them are correctly
displayed while one doesn't. I've written :
-*- coding: utf-8 -*-

Is this wrong ?

Where can I find a pratical explanation about these encodings ?

The coding line tell the interpreter to assume that the file is encoded as
utf-8. It's the job of the editor that you are using, to actually encode
the file as utf-8.
The coding directive uses a format that is automatically recognized by the
emacs editor. If you are using another editor, you'll have to search its
menus for the proper way to save files as utf-8.
 
J

John Machin

Benjamin said:
cantabile wrote:




The coding line tell the interpreter to assume that the file is encoded as
utf-8. It's the job of the editor that you are using, to actually encode
the file as utf-8.
The coding directive uses a format that is automatically recognized by the
emacs editor. If you are using another editor, you'll have to search its
menus for the proper way to save files as utf-8.

or possibly the OP needs to nut out what is the encoding he already has,
and tell Python what that encoding is.
 
P

Paul Watson

cantabile said:
Hi, being a newbie in Python, I'm a bit lost with the '-*- coding : -*-'
directive.

I'm using an accented characters language. Some of them are correctly
displayed while one doesn't. I've written :
-*- coding: utf-8 -*-

Is this wrong ?

Where can I find a pratical explanation about these encodings ?

Thanks.

You must know the encoding produced by your editor.

If you want to experiment, you could save a small file and run

od -Ax -tx1 thefile.py

to see exactly what codepoints appear. Compare those with the
charts at http://www.unicode.org/ and you can probably surmize
a good guess.
 
J

John Machin

Paul said:
You must know the encoding produced by your editor.

If you want to experiment, you could save a small file and run

od -Ax -tx1 thefile.py

to see exactly what codepoints appear. Compare those with the
charts at http://www.unicode.org/ and you can probably surmize
a good guess.

Perhaps faster, and certainly available on all platforms (unlike "od"):

Fire up Idle, then do this:

Why Idle, and not from the command line? Well because if you are on
Windows, you'll get a different answer, which is very unlikely to be the
one you want [unless you are using a legacy editor].

C:\junk>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
 

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

Forum statistics

Threads
474,262
Messages
2,571,311
Members
47,986
Latest member
ColbyG935

Latest Threads

Top