Python Frequently Asked Questions, Release 3.9.5 Chapter 4. Library and Extension FAQ 50 Don’t do this for CGI scripts. The$_{PATH}$ variable for CGI scripts is often very minimal, so you need to use the actual absolute pathname of the interpreter. Occasionally, a user’s environment is so full that the$_{/usr/bin/env}$ program fails; or there’s no env program at all. In that case, you can try the following hack (due to Alex Rezinsky): The minor disadvantage is that this defines the script’s __doc__ string. However, you can fix that by adding For Unix variants: The standard Python source distribution comes with a curses module in the Modules subdirectory, though it’s not compiled by default. (Note that this is not available in the Windows distribution – there is no curses module for Windows.) The curses module supports basic curses features as well as many additional functions from ncurses and SYSV curses such as colour, alternative character set support, pads, and mouse support. This means the module isn’t com- patible with operating systems that only have BSD curses, but there don’t seem to be any currently maintained OSes that fall into this category. For Windows: use the consolelib module. The$_{atexit}$module provides a register function that is similar to C’s$_{onexit()}$ . The most common problem is that the signal handler is declared with the wrong argument list. It is called as handler(signum, frame) so it should be declared with two parameters: def handler(signum, frame): ... Python comes with two testing frameworks. The$_{doctest}$module finds examples in the docstrings for a module and runs them, comparing the output with the expected output given in the docstring. The$_{unittest}$module is a fancier testing framework modelled on Java and Smalltalk testing frameworks. To make testing easier, you should use good modular design in your program. Your program should have almost all functionality encapsulated in either functions or class methods – and this sometimes has the surprising and delightful effect of making the program run faster (because local variable accesses are faster than global accesses). Furthermore the program should avoid depending on mutating global variables, since this makes testing much more difficult to do. 4.2.1 How do I test a Python program or component? 4.2 Common tasks 4.1.6 Why don’t my signal handlers work? 4.1.5 Is there an equivalent to C’s onexit() in Python? 4.1.4 Is there a curses/termcap package for Python? __doc__=""" ...Whatever... """ #! /bin/sh "" ":" exec python $0 ${ 1+"$@" } "" "