Message286414
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." |
|
Date |
User |
Action |
Args |
2017-01-28 16:39:15 | marco.buttu | set | recipients:
+ marco.buttu, rhettinger, docs@python, Jim Fasarakis-Hilliard, Mariatta |
2017-01-28 16:39:15 | marco.buttu | set | messageid: <1485621555.71.0.804366646736.issue29381@psf.upfronthosting.co.za> |
2017-01-28 16:39:15 | marco.buttu | link | issue29381 messages |
2017-01-28 16:39:15 | marco.buttu | create | |
|