next up previous contents
Next: Copying: the copy module Up: Using Modules Previous: Expansion of Filename wildcards   Contents


Information about your Python session - the sys module

Information about the current Python session is provided through a number of variables contained in the sys module. File objects for the three basic input and output streams are stored in the variables stdin (standard input), stdout (standard output), and stderr (standard error); details of their use is presented in Section 5.5.

The array argv contains any arguments which were passed to your python program, if it were called from the command line. The first element of this array (argv[0]) contains the name of the script which is executing, or an empty string if you are entering commands in the python interpreter. (The getopt module can be used to aid in parsing command line flags and arguments.)

The array path contains the names of the directories which will be searched when you use an import statement. If you need to import a module which is stored in a non-standard directory, you can simply append the name of the directory to path before issuing an import command that utilizes the non-standard directory. Keep in mind that the environmental variable PYTHONPATH provides a means for automatically updating the Python system path each time that you invoke Python.

The function object exitfunc will be called immediately before the interpreter exits. Note that this is an actual function object, not just the name of a function to be called. No arguments should be passed to the function stored in exitfunc.

Finally, the exit function of the sys module allows you to terminate the current Python session. An optional integer argument represents an error code; the value zero is used to indicate normal completion.


next up previous contents
Next: Copying: the copy module Up: Using Modules Previous: Expansion of Filename wildcards   Contents
Phil Spector 2003-11-12