E. Execution - JulTob/Python GitHub Wiki
Options
An option, or command-line switch, begins with a minus sign followed by one or more letters. For example, if you want to obtain help about Python, you type Python –h and press Enter. You see additional information about how to work with Python at the command line. The options are described later in this section.
-b Add warnings to the output when your application uses certain Python features that include: str(bytes_instance), str(bytearray_instance), and comparing bytes or bytearray with str().
-bb: Add errors to the output when your application uses certain Python features that include: str(bytes_instance), str(bytearray_instance), and comparing bytes or bytearray with str().
-B: Don’t write .py or .pyco files when performing a module import.
-c cmd: Use the information provided by cmd to start a program. This option
also tells Python to stop processing the rest of the information as options (it’s
treated as part of the command).
-d Start the debugger (used to locate errors in your application).
-E Ignore all the Python environment variables, such as PYTHONPATH.
-h Print help message and exit.
-i Enter interactive mode after executing a script.
» -m mod: Run the library module specified by mod as a script. This option also
tells Python to stop processing the rest of the information as options (the rest
of the information is treated as part of the command).
-O Optimize the generated bytecode. Creates and uses .pyo byte-code files.
-OO Perform additional optimization by removing doc-strings.
-q Not to print the version and copyright messages on interactive startup.
-s Do not add the user site directory to the sys.path module search path. A variable that tells Python where to find modules.
-S Don’t run 'import site' on initialization. Using this option means that Python won’t look for paths that may contain modules it needs.
» -u: Allow unbuffered binary input for the stdout (standard output) and
stderr (standard error) devices. The stdin device is always buffered.
» -v: Place Python in verbose mode so that you can see all the import state-
ments. Using this option multiple times increases the level of verbosity.
» -V: Display the Python version number and exit.
» --version: Display the Python version number and exit.
» -W arg: Modify the warning level so that Python displays more or fewer
warnings. The valid arg values are
• action
• message
• category
• module
• lineno
» -x: Skip the first line of a source code file, which allows the use of non-Unix
forms of #!cmd.
» -X opt: Set an implementation-specific option. (The documentation for your
version of Python discusses these options, if there are any.)
# Environment Variables
Using environment variables makes sense when you need to configure Python the
same way on a regular basis. The following list describes the Python environment
variables:
» PYTHONCASEOK=x: Forces Python to ignore case when parsing import
statements. This is a Windows-only environment variable.
» PYTHONDEBUG=x: Performs the same task as the -d option.
» PYTHONDONTWRITEBYTECODE=x: Performs the same task as the -B option.
» PYTHONFAULTHANDLER=x: Forces Python to dump the Python traceback (list of
calls that led to an error) on fatal errors.
» PYTHONHASHSEED=arg: Determines the seed value used to generate hash
values from various kinds of data. When this variable is set to random, Python
uses a random value to seed the hashes of str, bytes, and datetime objects.
The valid integer range is 0 to 4294967295. Use a specific seed value to obtain
predictable hash values for testing purposes.
» PYTHONHOME=arg: Defines the default search path that Python uses to look
for modules.
» PYTHONINSPECT=x: Performs the same task as the -i option.
» PYTHONIOENCODING=arg: Specifies the encoding[:errors] (such as utf-8)
used for the stdin, stdout, and stderr devices.
» PYTHONNOUSERSITE: Performs the same task as the -s option.
» PYTHONOPTIMIZE=x: Performs the same task as the -O option.
» PYTHONPATH=arg: Provides a semicolon (;) separated list of directories to
search for modules. This value is stored in the sys.path variable in Python.
CHAPTER 3 Interacting with Python 43
» PYTHONSTARTUP=arg: Defines the name of a file to execute when Python
starts. There is no default value for this environment variable.
» PYTHONUNBUFFERED=x: Performs the same task as the -u option.
» PYTHONVERBOSE=x: Performs the same task as the -v option.
» PYTHONWARNINGS=arg: Performs the same task as the -W option.