How to define python source code encoding?

While using non-ASCII characters in your code, you might get this error: "SyntaxError: Non-ASCII character '\xc3' in file myprog.py on line 101, but no encoding declared;".

Solution is to define encoding at the beginning of your source code.

Syntax: # -*- coding: desired_encoding -*-
Example: # -*- coding: iso-8859-1 -*-

For details check http://www.python.org/dev/peps/pep-0263/.

Comments

Popular posts from this blog

lambda magic to find prime numbers

Convert text to ASCII and ASCII to text - Python code

Adjacency Matrix (Graph) in Python