Last Updated: February 25, 2016
·
516
· josetomastocino

Have some fun with Python encoding headers

If you've ever wondered what those encoding: utf-8 comments were at the top of Python files, they're defined in PEP 0263. If you take a closer look, it says that the comment must match this regexp: coding[:=]\s*([-\w.]+).

That's cool, because you can start your python files with things like:

# There was a tale about rococoding: utf-8 was the most powerful warrior 

print "Heló"

Or

# There's one thing I know about encoding: utf-8 sucks!

And it will still be a valid encoding header lol