Some of the python source file starts with
-*- coding: utf-8 -*-. This particular linetells python interpreter all the content (byte string) is
utf-8 encoded. Lets see how it affects the code.
# -*- coding: utf-8 -*- print("welcome") print("animé")
➜ code$ python2 uni1.py welcome animé
Third line had a accented character and it wasn’t explictly stated as unicode.
utf-8, so it worked.
What if first line was missing ?
code$ python2 uni2.py File "uni2.py", line 2 SyntaxError: Non-ASCII character '\xc3' in file uni2.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Now python complains that Non-ASCII character is found since default encoding is ASCII.More about source encoding can be found in PEP 263
encoding in first or second line of python file.
- Five reasons to use Py.test
- Build Plugins with Pluggy
- Render local images in datasette using datasette-render-local-images
- Parameterize Python Tests
- “Don’t touch your face” - Neural Network will warn you
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.