[New-bugs-announce] [issue13525] Tutorial: Example of Source Code Encoding triggers error

Nicolas Goutte report at bugs.python.org
Sat Dec 3 14:17:22 CET 2011

New submission from Nicolas Goutte <nicolas.goutte at extragroup.de>:

Current Behaviour

The tutorial of Python 3.2.x has an example to set an encoding in a source file: http://docs.python.org/py3k/tutorial/interpreter.html#source-code-encoding

It explains to set the following line at the start of the source code:
# -*- coding: cp-1252 -*-

However when done exactly so, Python raises the following exception:
SyntaxError: encoding problem: with BOM

The problem seems to be that Python knows Windows codepage 1252 as windows-1252 (its IANA charset name, see http://www.iana.org/assignments/charset-reg/windows-1252 ) or alternatively as cp1252 (without dash) but not as cp-1252 (with dash).

As this is an example in the tutorial is particularly problematic, as users might not understand how to do it correctly.

This is still the case in the tutorial of Python 3.3 alpha: http://docs.python.org/dev/tutorial/interpreter.html#source-code-encoding

Expected Behaviour

The tutorial should give a correct example, for example with:
# -*- coding: windows-1252 -*-

Alternatively a totally other example as for Python 2.7 would be nice too: http://docs.python.org/tutorial/interpreter.html#source-code-encoding

I have tested this with following Python implementations:
- Python 3.2.1 (openSUSE 12.1) on Linux
- Python 3.2.2 on Windows 7 SP1 64 Bits
- Python 3.2.2 on MacOS 10.5.8
(Always on the command line; I have not tested in IDLE.)

assignee: docs at python
components: Documentation
files: cp_1252broken.py
messages: 148798
nosy: docs at python, nicolasg
priority: normal
severity: normal
status: open
title: Tutorial: Example of Source Code Encoding triggers error
versions: Python 3.2
Added file: http://bugs.python.org/file23840/cp_1252broken.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list