Archive

Problem
Your project directories are littered with .pyc files. How to tell the interpreter to stop creating them?

Solution
Since Python 2.6:

“Python can now be prevented from writing .pyc or .pyo files by supplying the -B switch to the Python interpreter, or by setting the PYTHONDONTWRITEBYTECODE environment variable before running the interpreter. This setting is available to Python programs as the sys.dont_write_bytecode variable, and Python code can change the value to modify the interpreter’s behaviour.” (tip from here)

According to the FAQ, Python Central “…serves as a central place for Python enthusiasts, for anything and everything to do with the Python programming language. The content on the site is a combination of documentation of the library, a guide to learning the language, tips and tricks, and recipes.“

Docopt is a parser for command line arguments. There are other alternatives like optparse and argparse but docopt is the king. Why? Because it cannot be any simpler :) All you have to do is write an interface description to your script that is well-known from man pages and from the help of other command line applications.

Then you simply pass this string to docopt. When you execute the script, the parameters will be parsed by docopt according to the textual description above. Say you launch this script with the following parameters: