Python header

This post is about what to put on top of your Python script. You may have seen Python script starting with something like:

# coding: latin-1

and wonder what it is useful for or do you need it.

The first line make your script possibly executable by telling your system where to find the python executable. Under linux, if you changed the permission of the file to executable (chmod 755 they you can simply type the name of the script (without python in front of it).

The second line is related to the characters that will be found ib the script.By default the encoding is utf-8 but if you want to use another one you must specify it.

The encoding must be specified on the first or second line of the script and using one of these syntax:

# coding: latin-1
# -*- coding: latin-1 -*-

Reference: pep-0263

Please follow and like us:
This entry was posted in Python and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.