Python Windows release and encoding
Peter Otten
__peter__ at web.de
Wed May 22 08:39:15 EDT 2013
Absalom K. wrote:
> Hi, I am working on Linux; a friend of mine sends to me python files from
> his Windows release. He uses the editor coming with the release; he runs
> his code from the editor by using a menu (or some F5 key I think).
>
> He doesn't declare any encoding in his source file; when I want to try
> his code, I have an error since he obviously uses non-ascii characters.
> As far as I can see, he uses utf8 without knowing it. I add the UTF8
> declaration, run the code, and everything is fine.
>
> Then I tell him to add the utf-8 declaration; but now he has an error
> when running his file from the Windows editor.
>
> Finally, he told me he could run the file by declaring the latin-1
> encoding.
>
> But I want to understand exactly:
> a) what is the encoding used by the editor coming in the Windows
> release? b) why doesn't he need to declare the encoding (I need it on
> Linux for
> the very same files)?
>
> Best regards, ak.
Your friend may be using an old version of Python. Quoting
<http://www.python.org/dev/peps/pep-0263/>
"""
For backwards-compatibility with existing code which currently
uses non-ASCII in string literals without declaring an encoding,
the implementation will be introduced in two phases:
1. Allow non-ASCII in string literals and comments, by internally
treating a missing encoding declaration as a declaration of
"iso-8859-1". This will cause arbitrary byte strings to
correctly round-trip between step 2 and step 5 of the
processing, and provide compatibility with Python 2.2 for
Unicode literals that contain non-ASCII bytes.
A warning will be issued if non-ASCII bytes are found in the
input, once per improperly encoded input file.
2. Remove the warning, and change the default encoding to "ascii".
[...]
Implementation of steps 1 and 2 above were completed in 2.3,
except for changing the default encoding to "ascii".
The default encoding was set to "ascii" in version 2.5.
"""
More information about the Python-list
mailing list