[issue27797] ASCII file with UNIX line conventions and enough lines throws SyntaxError when ASCII-compatible codec is declared

Martijn Pieters report at bugs.python.org
Fri Aug 19 03:38:02 EDT 2016


New submission from Martijn Pieters:

To reproduce, create an ASCII file with > io.DEFAULT_BUFFER_SIZE bytes (can be blank lines) and *UNIX line endings*, with the first two lines reading:

  #!/usr/bin/env python
  # -*- coding: cp1252 -*-

Try to run this as a script on Windows:

    C:\Python35\python.exe encoding-problem-cp1252.py
     File "encoding-problem-cp1252.py", line 2
    SyntaxError: encoding problem: cp1252

Converting the file to use CRLF (Windows) line endings makes the problem go away.

This appears to be a fallout from issue #20731.

Demo file that reproduces this issue at 710 bytes: https://github.com/techtonik/testbin/raw/fbb8aec3650b45f690c4febfd621fe5d6892b14a/python/encoding-problem-cp1252.py

First reported by anatoly techtonik at https://stackoverflow.com/questions/39032416/python-3-5-syntaxerror-encoding-prob-em-cp1252

----------
components: Interpreter Core, Windows
messages: 273087
nosy: mjpieters, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: ASCII file with UNIX line conventions and enough lines throws SyntaxError when ASCII-compatible codec is declared
versions: Python 3.4, Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27797>
_______________________________________


More information about the Python-bugs-list mailing list