1. Command line and environment — Python 3.11.16 documentation

docs.python.org

Tin mới

Python Setup and Usage

2. Using Python on Unix platforms

Python Module Index

3.11.16 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 top-level code is run. Covers command-line interfaces, import-time behavior, and ``__name__ == '__main__'``.

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.

faulthandler: Dump the Python traceback.

-X faulthandler to enable faulthandler. See also PYTHONFAULTHANDLER.

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. See also PYTHONDEVMODE.

installation paths

Defines the user base directory, which is used to compute the path of the user site-packages directory and installation paths for python -m pip 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

filesystem encoding and error handler

If set to a non-empty string, the default filesystem encoding and error handler mode will revert to their pre-3.6 values of ‘mbcs’ and ‘replace’, respectively. Otherwise, the new defaults ‘utf-8’ and ‘surrogatepass’ are

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.

Opt-in EncodingWarning

If this environment variable is set to a non-empty string, issue a EncodingWarning when the locale-specific default encoding is used.

debug build of Python

If set, Python will print threading debug info into stdout.