Unable to run print('Réussi') on windows and on linux
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Aug 14 11:21:41 EDT 2014
YBM wrote:
> Le 14/08/2014 16:04, marc.vanhoomissen at gmail.com a écrit :
>> Hello YBM,
>> I tried your suggestions, without improvement.
>> Further, see my answer to Vincent Vande Vyre
>> Thanks anyway.
>
> This is indeed very surprising. Are you sure that you
> have *exactly* this line at the first or second (not
> later !) line of your script :
>
> # -*- encoding: utf-8 -*-
>
> if a single caracter differs, it would fail.
That's not correct. The encoding declaration is very flexible. Any of these
will be accepted:
# This file uses the encoding: utf_8
# coding=UTF-8
# -*- coding: utf8 -*-
# vim: set fileencoding=utf-8 :
# Uses encoding:utf8
# I want my encoding=UtF_8 okay!
#### textencoding= UTf-8 blah blah blah
and many, many other varieties. The rules are:
(1) It must be a comment;
(2) It must be in the first or second line of the file;
(3) It must match the regular expression r"coding[:=]\s*([-\w.]+)"
However, just because you declare the file to be UTF-8, doesn't mean it
*actually is* UTF-8. If your text editor is configured to use (say)
Latin-1, a UTF-8 encoding declaration will just give you garbage.
* Fix your system to use UTF-8 by default.
* Fix your editor to use UTF-8.
* Add a UTF-8 encoding declaration.
And then things should work.
--
Steven
More information about the Python-list
mailing list