This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author marco.buttu
Recipients Jim Fasarakis-Hilliard, Mariatta, docs@python, marco.buttu, rhettinger
Date 2017-01-28.16:39:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1485621555.71.0.804366646736.issue29381@psf.upfronthosting.co.za>
In-reply-to
Content
You wrote: "It is also possible to specify a different encoding for source files. In order to do this, you can use a special comment line that defines the source file encoding::". I think that is not true, because the line have to be the first line, or right below a comment (just one, as in the case of the shebang). For instance, in this case Python apply the declared coding:

  $ cat foo.py
  # The first line is a comment
  # -*- coding: ascii -*-
  print('è')  # Encoded in UTF-8
  $ python foo.py
     ...
  SyntaxError: encoding problem: ascii


In this case it does not:

  $ cat foo.py
  # The first line is a comment
  # and also the sencond line
  # -*- coding: ascii -*-
  print('è')  # Encoded in UTF-8
  $ python foo.py 
  è

But I think you are right that the current doc is confusing. Maybe yon can write something like this: 

"It is also possible to specify a different encoding for source files. In order to do this, put one special comment line to define the source file encoding:

# -*- coding: encoding -*-

This coding comment has to be the first line of the file, or the second line in case the first one is the #! line."
History
Date User Action Args
2017-01-28 16:39:15marco.buttusetrecipients: + marco.buttu, rhettinger, docs@python, Jim Fasarakis-Hilliard, Mariatta
2017-01-28 16:39:15marco.buttusetmessageid: <1485621555.71.0.804366646736.issue29381@psf.upfronthosting.co.za>
2017-01-28 16:39:15marco.buttulinkissue29381 messages
2017-01-28 16:39:15marco.buttucreate