By default, Python cannot deal with non-ASCII characters in source files, such as the following line:
re.sub("ae", u'ä', "haette") # SyntaxError: Non-ASCII character '\xc3' in file <file>.py on line <line>, but no # encoding declared; see http://legacy.python.org/dev/peps/pep-0263/ for details
The file encoding can be signalized by adding a magic comment in either the first or second line of the file:
#!/usr/bin/bash # -*- coding: utf-8 -*
References
- [1] More information in the Python Enhancement Proposals index