A few users have asked why the wscript files usually include the following header if they are not meant to be executed directly:

#! /usr/bin/env python
# encoding: utf-8

Several benefits have been observed over the time, and it appears that this header is a best practice:

  • Most text editors - especially on unix-like systems - will read the first line beginning by #! to apply proper syntax highlighting. Your text editor may well display the file properly, but others may not.
  • If the wscript files are ever meant to be executed, then:
    1. The process will not hang when called as ./wscript (the 'import' program takes screenshots)
    2. The /usr/bin/env will redirect the interpreter to the adequate python executable (python can be installed in /usr/local or /opt for example)
  • The encoding declaration will prevent special characters such as €, é or í from causing errors

When a wscript file is created for the first time, it may have to be reloaded to force the text editor to take the file type into account. In Vim at least, a mapping can be added to save the hassle of re-opening the file:

au BufNewFile,BufRead wscript* set filetype=python