1. Command line and environment — Python 3.9.25 documentation

docs.python.org

Tin mới

Python Setup and Usage

2. Using Python on Unix platforms

Python documentation for the current stable release

The CPython interpreter scans the command line and the environment for various settings.

Python Module Index

3.9.25 Documentation

Alternate Implementations

CPython implementation detail: Other implementations’ command line schemes may differ. See Alternate Implementations for further resources.

1.1.1. Interface options¶

The interpreter interface resembles that of the UNIX shell, but provides some additional methods of invocation:

__main__: The environment where the top-level script is run.

Search sys.path for the named module and execute its contents as the __main__ module.

timeit: Measure the execution time of small code snippets.

Search sys.path for the named module and execute its contents as the __main__ module.

runpy.run_module()

Equivalent functionality directly available to Python code

Readline configuration

The interpreter interface resembles that of the UNIX shell, but provides some additional methods of invocation:

Invoking the Interpreter

Cached bytecode invalidation

The semantics of timestamp-based .pyc files are unaffected by this option.

warnings: Issue warning messages and control their disposition.

Warning control. Python’s warning machinery by default prints warning messages to sys.stderr. A typical warning message has the following form:

faulthandler: Dump the Python traceback.

tracemalloc: Trace memory allocations.

-X tracemalloc to start tracing Python memory allocations using the tracemalloc module. By default, only the most recent frame is stored in a traceback of a trace. Use -X tracemalloc=NFRAME to start tracing with a traceb

integer string conversion length limitation

-X int_max_str_digits configures the integer string conversion length limitation. See also PYTHONINTMAXSTRDIGITS.

Python Development Mode

-X dev: enable Python Development Mode, introducing additional runtime checks that are too expensive to be enabled by default.

Distutils installation paths

Defines the user base directory, which is used to compute the path of the user site-packages directory and Distutils installation paths for python setup.py install --user.

asyncio: Asynchronous I/O.

If this environment variable is set to a non-empty string, enable the debug mode of the asyncio module.

default memory allocators

locale.getdefaultlocale()

If set to the value 0, causes the main Python command line application to skip coercing the legacy ASCII-based C and POSIX locales to a more capable UTF-8 based alternative.