PYTHON(1)

๐Ÿ“ฆ
version 3.11.17 ยท 3 versions
, in centos-stream 9, fedora 43, fedora 44

๐ŸŒธ PYTHON(1) โ€” General Commands Manual ๐ŸŒธ

okay bestie, buckle up, because this is the manual page for python itself, and she's that girl. ๐Ÿ’…


โœจ NAME โœจ

python โ€” an interpreted, interactive, object-oriented programming language

like. that's the whole vibe. an interpreted, interactive, object-oriented programming language. main character energy fr fr. ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

python [ -B ] [ -b ] [ -d ] [ -E ] [ -h ] [ -i ] [ -I ]
       [ -m module-name ] [ -q ] [ -O ] [ -OO ] [ -P ] [ -s ] [ -S ] [ -u ]
       [ -v ] [ -V ] [ -W argument ] [ -x ] [ -X option ] [ -?  ]
       [ --check-hash-based-pycs default | always | never ]
       [ --help ] [ --help-env ] [ --help-xoptions ] [ --help-all ]
       [ -c command | script | - ] [ arguments ]

so many flags. she contains multitudes. we'll get to every single one, don't worry, i'm not skipping a crumb. ๐Ÿ“


โœจ DESCRIPTION โœจ

okay so. Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax. like, both. at the same time. iconic behavior honestly. โœจ

if you're new to programming in Python and you want an intro, go read the Python Tutorial. if you want the built-in and standard types, constants, functions and modules documented, that's the Python Library Reference. and finally, the Python Reference Manual describes the syntax and semantics of the core language in โ€” and this is a direct quote, bestie โ€” (perhaps too) much detail. ๐Ÿ˜ญ the manual literally said that about itself. self-aware queen.

these documents can be located via the INTERNET RESOURCES listed below, and they may also be installed on your system. so check both, no cap.

Python's basic power can be extended with your own modules written in C or C++. on most systems, those modules may be dynamically loaded. ๐Ÿฆ‹ Python is also adaptable as an extension language for existing applications โ€” see the internal documentation for hints, iykyk.

last thing for this section: documentation for installed Python modules and packages can be viewed by running the pydoc program. go look at it. it's giving built-in help desk and it slays. ๐Ÿ’–


โœจ COMMAND LINE OPTIONS โœจ

ok bestie, this is the part where Python lets you boss it around. every single flag, no skips, let's go ๐Ÿ’…

  • -B โ€” don't write .pyc files on import. see also PYTHONDONTWRITEBYTECODE. (yes queen, no bytecode crumbs left behind ๐Ÿงน)
  • -b โ€” issue warnings about str(bytes_instance), str(bytearray_instance) and comparing bytes/bytearray with str. (-bb: issue errors instead โ€” glow up to full tantrum mode ๐Ÿ˜ค)
  • -c command โ€” specify the command to execute (peep the next section for the deets). this terminates the option list, so everything after it gets passed as arguments to the command. periodt.
  • --check-hash-based-pycs mode โ€” configure how Python evaluates the up-to-dateness of hash-based .pyc files. (the vibe check for your pycs, literally โœจ)
  • -d โ€” turn on parser debugging output (for experts only, and it depends on compilation options โ€” so don't come crying if nothing happens ๐Ÿ™ˆ)
  • -E โ€” ignore environment variables like PYTHONPATH and PYTHONHOME that modify the behavior of the interpreter. (blocked. no env vars allowed to touch you today ๐Ÿšซ)
  • -h, -?, --help โ€” prints the usage for the interpreter executable and exits.
  • --help-env โ€” prints help about Python-specific environment variables and exits.
  • --help-xoptions โ€” prints help about implementation-specific -X options and exits.
  • --help-all โ€” prints complete usage information and exits. (the whole lore drop ๐Ÿ“š)
  • -i โ€” when a script is passed as first argument or the -c option is used, enter interactive mode after executing the script or the command. it does not read the $PYTHONSTARTUP file. this can be useful to inspect global variables or a stack trace when a script raises an exception. (main character energy: you stay in the room after the scene ends ๐Ÿ‘‘)
  • -I โ€” run Python in isolated mode. this also implies -E, -P and -s. in isolated mode sys.path contains neither the script's directory nor the user's site-packages directory. all PYTHON* environment variables are ignored, too. further restrictions may be imposed to prevent the user from injecting malicious code. (so safe it's giving bunker ๐Ÿ›ก๏ธ)
  • -m module-name โ€” searches sys.path for the named module and runs the corresponding .py file as a script. this terminates the option list, so following options are passed as arguments to the module.
  • -O โ€” remove assert statements and any code conditional on the value of __debug__; augment the filename for compiled (bytecode) files by adding .opt-1 before the .pyc extension.
  • -OO โ€” do -O and also discard docstrings; change the filename for compiled (bytecode) files by adding .opt-2 before the .pyc extension. (double optimized, double iconic ๐Ÿ’€)
  • -P โ€” don't automatically prepend a potentially unsafe path to sys.path such as the current directory, the script's directory or an empty string. see also the PYTHONSAFEPATH environment variable.
  • -q โ€” do not print the version and copyright messages. these messages are also suppressed in non-interactive mode. (quiet luxury ๐Ÿคซ)
  • -s โ€” don't add user site directory to sys.path.
  • -S โ€” disable the import of the module site and the site-dependent manipulations of sys.path that it entails. also disable these manipulations if site is explicitly imported later.
  • -u โ€” force the stdout and stderr streams to be unbuffered. this option has no effect on the stdin stream. (stdin said not today ๐Ÿ™…โ€โ™€๏ธ)
  • -v โ€” print a message each time a module is initialized, showing the place (filename or built-in module) from which it is loaded. when given twice, print a message for each file that is checked for when searching for a module. also provides information on module cleanup at exit. (spill the tea on every module ๐Ÿต)
  • -V, --version โ€” prints the Python version number of the executable and exits. when given twice, print more information about the build.
  • -W argument โ€” warning control. Python's warning machinery by default prints warning messages to sys.stderr.

the simplest settings apply a particular action unconditionally to all warnings emitted by a process (even those that are otherwise ignored by default):

-Wdefault  # Warn once per call location
-Werror    # Convert to exceptions
-Walways   # Warn every time
-Wmodule   # Warn once per calling module
-Wonce     # Warn once per Python process
-Wignore   # Never warn

the action names can be abbreviated as desired and the interpreter will resolve them to the appropriate action name. for example, -Wi is the same as -Wignore. (so you can be lazy, it's fine, we support you ๐Ÿ’–)

the full form of argument is:

action:message:category:module:lineno

empty fields match all values; trailing empty fields may be omitted. for example -W ignore::DeprecationWarning ignores all DeprecationWarning warnings.

the action field is as explained above but only applies to warnings that match the remaining fields.

the message field must match the whole printed warning message; this match is case-insensitive.

the category field matches the warning category (ex: "DeprecationWarning"). this must be a class name; the match test whether the actual warning category of the message is a subclass of the specified warning category.

the module field matches the (fully-qualified) module name; this match is case-sensitive.

the lineno field matches the line number, where zero matches all line numbers and is thus equivalent to an omitted line number.

multiple -W options can be given; when a warning matches more than one option, the action for the last matching option is performed. invalid -W options are ignored (though, a warning message is printed about invalid options when the first warning is issued).

warnings can also be controlled using the PYTHONWARNINGS environment variable and from within a Python program using the warnings module. for example, the warnings.filterwarnings() function can be used to use a regular expression on the warning message.

  • -X option โ€” set implementation-specific option. the following options are available:
    • -X faulthandler: enable faulthandler
    • -X showrefcount: output the total reference count and number of used memory blocks when the program finishes or after each statement in the interactive interpreter. this only works on debug builds
    • -X tracemalloc: 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 traceback limit of NFRAME frames
    • -X importtime: show how long each import takes. it shows module name, cumulative time (including nested imports) and self time (excluding nested imports). note that its output may be broken in multi-threaded application. typical usage is python3 -X importtime -c 'import asyncio'
    • -X dev: enable CPython's "development mode", introducing additional runtime checks which are too expensive to be enabled by default. it will not be more verbose than the default if the code is correct: new warnings are only emitted when an issue is detected. effect of the developer mode:
      • Add default warning filter, as -W default
      • Install debug hooks on memory allocators: see the PyMem_SetupDebugHooks() C function
      • Enable the faulthandler module to dump the Python traceback on a crash
      • Enable asyncio debug mode
      • Set the dev_mode attribute of sys.flags to True
      • io.IOBase destructor logs close() exceptions
    • -X utf8: enable UTF-8 mode for operating system interfaces, overriding the default locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode (even when it would otherwise activate automatically). see PYTHONUTF8 for more details
    • -X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted at the given directory instead of to the code tree.
    • -X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None'
    • -X no_debug_ranges: disable the inclusion of the tables mapping extra location information (end line, start column offset and end column offset) to every instruction in code objects. this is useful when smaller code objects and pyc files are desired as well as suppressing the extra visual location indicators when the interpreter displays tracebacks.
    • -X frozen_modules=[on|off]: whether or not frozen modules should be used. the default is "on" (or "off" if you are running a local build).
    • -X int_max_str_digits=number: limit the size of int<->str conversions. this helps avoid denial of service attacks when parsing untrusted data. the default is sys.int_info.default_max_str_digits. 0 disables.
  • -x โ€” skip the first line of the source. this is intended for a DOS specific hack only.
โš ๏ธ Warning: the line numbers in error messages will be off by one! (not the vibe, but here we are ๐Ÿ˜ญ)

โœจ INTERPRETER INTERFACE โœจ

ok so the interpreter interface is basically giving UNIX shell energy ๐Ÿ’… โ€” like, it works the same way. When you call it with standard input hooked up to a tty device, it's gonna prompt you for commands and run them until it reads an EOF. When you call it with a file name argument, or with a file as standard input, it reads and executes a script from that file. And when you call it with -c command, it executes the Python statement(s) you gave as command. ๐Ÿซถ

Heads up bestie: command can contain multiple statements, separated by newlines. And leading whitespace is significant in Python statements! Like, the indentation is the whole vibe, don't touch it. ๐Ÿ˜ญ Also, in non-interactive mode, the entire input is parsed before any of it is executed.

If available, the script name and any additional arguments after it get passed to the script in the Python variable sys.argv, which is a list of strings โ€” and yes, you have to import sys first to access it, it's not just gonna show up. ๐Ÿ™ˆ If no script name is given, sys.argv[0] is an empty string; if -c is used, sys.argv[0] contains the string '-c'. And ngl, options interpreted by the Python interpreter itself do not get placed in sys.argv โ€” they're not part of the cast.

In interactive mode, the primary prompt is >>>; the second prompt (the one that shows up when a command isn't complete yet) is .... You can change these prompts by assigning to sys.ps1 or sys.ps2 โ€” make them whatever you want, main character energy only. ๐Ÿ‘‘

The interpreter quits when it reads an EOF at a prompt. When an unhandled exception happens, a stack trace gets printed and control returns to the primary prompt; but in non-interactive mode, the interpreter just exits after printing the stack trace. The interrupt signal raises the KeyboardInterrupt exception; other UNIX signals are not caught (except that SIGPIPE is sometimes ignored, in favor of the IOError exception). Error messages are written to stderr. ๐Ÿ’€


๐ŸŒธ FILES AND DIRECTORIES ๐ŸŒธ

These are subject to difference depending on local installation conventions; ${prefix} and ${exec_prefix} are installation-dependent and should be interpreted as for GNU software; they may be the same. The default for both is /usr/local. โœจ

  • ${exec_prefix}/bin/python โ€” Recommended location of the interpreter. ๐Ÿ
  • ${prefix}/lib/python<version>
  • ${exec_prefix}/lib/python<version>

Recommended locations of the directories containing the standard modules.

  • ${prefix}/include/python<version>
  • ${exec_prefix}/include/python<version>

Recommended locations of the directories containing the include files needed for developing Python extensions and embedding the interpreter.


๐Ÿฆ‹ ENVIRONMENT VARIABLES ๐Ÿฆ‹

  • PYTHONSAFEPATH โ€” If this is set to a non-empty string, don't automatically prepend a potentially unsafe path to sys.path such as the current directory, the script's directory or an empty string. See also the -P option.
  • PYTHONHOME โ€” Change the location of the standard Python libraries. By default, the libraries are searched in ${prefix}/lib/python<version> and ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix} are installation-dependent directories, both defaulting to /usr/local. When $PYTHONHOME is set to a single directory, its value replaces both ${prefix} and ${exec_prefix}. To specify different values for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
  • PYTHONPATH โ€” Augments the default search path for module files. The format is the same as the shell's $PATH: one or more directory pathnames separated by colons. Non-existent directories are silently ignored. The default search path is installation dependent, but generally begins with ${prefix}/lib/python<version> (see PYTHONHOME above). The default search path is always appended to $PYTHONPATH. If a script argument is given, the directory containing the script is inserted in the path in front of $PYTHONPATH. The search path can be manipulated from within a Python program as the variable sys.path.
  • PYTHONPLATLIBDIR โ€” Override sys.platlibdir.
  • PYTHONSTARTUP โ€” If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode. The file is executed in the same name space where interactive commands are executed so that objects defined or imported in it can be used without qualification in the interactive session. You can also change the prompts sys.ps1 and sys.ps2 in this file. ๐ŸŽ€
  • PYTHONOPTIMIZE โ€” If this is set to a non-empty string it is equivalent to specifying the -O option. If set to an integer, it is equivalent to specifying -O multiple times.
  • PYTHONDEBUG โ€” If this is set to a non-empty string it is equivalent to specifying the -d option. If set to an integer, it is equivalent to specifying -d multiple times.
  • PYTHONDONTWRITEBYTECODE โ€” If this is set to a non-empty string it is equivalent to specifying the -B option (don't try to write .pyc files).
  • PYTHONINSPECT โ€” If this is set to a non-empty string it is equivalent to specifying the -i option.
  • PYTHONIOENCODING โ€” If this is set before running the interpreter, it overrides the encoding used for stdin/stdout/stderr, in the syntax encodingname:errorhandler. The errorhandler part is optional and has the same meaning as in str.encode. For stderr, the errorhandler part is ignored; the handler will always be ยดbackslashreplaceยด.
  • PYTHONNOUSERSITE โ€” If this is set to a non-empty string it is equivalent to specifying the -s option (Don't add the user site directory to sys.path).
  • PYTHONUNBUFFERED โ€” If this is set to a non-empty string it is equivalent to specifying the -u option.
  • PYTHONVERBOSE โ€” If this is set to a non-empty string it is equivalent to specifying the -v option. If set to an integer, it is equivalent to specifying -v multiple times.
  • PYTHONWARNINGS โ€” If this is set to a comma-separated string it is equivalent to specifying the -W option for each separate value.
  • PYTHONHASHSEED โ€” If this variable is set to "random", a random value is used to seed the hashes of str and bytes objects.

If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for generating the hash() of the types covered by the hash randomization. Its purpose is to allow repeatable hashing, such as for selftests for the interpreter itself, or to allow a cluster of python processes to share hash values.

The integer must be a decimal number in the range [0,4294967295]. Specifying the value 0 will disable hash randomization.

  • PYTHONINTMAXSTRDIGITS โ€” Limit the maximum digit characters in an int value when converting from a string and when converting an int back to a str. A value of 0 disables the limit. Conversions to or from bases 2, 4, 8, 16, and 32 are never limited.
  • PYTHONMALLOC โ€” Set the Python memory allocators and/or install debug hooks. The available memory allocators are malloc and pymalloc. The available debug hooks are debug, malloc_debug, and pymalloc_debug.

When Python is compiled in debug mode, the default is pymalloc_debug and the debug hooks are automatically used. Otherwise, the default is pymalloc.

  • PYTHONMALLOCSTATS โ€” If set to a non-empty string, Python will print statistics of the pymalloc memory allocator every time a new pymalloc object arena is created, and on shutdown.

This variable is ignored if the $PYTHONMALLOC environment variable is used to force the malloc(3) allocator of the C library, or if Python is configured without pymalloc support.

  • PYTHONASYNCIODEBUG โ€” If this environment variable is set to a non-empty string, enable the debug mode of the asyncio module.
  • PYTHONTRACEMALLOC โ€” If this environment variable is set to a non-empty string, start tracing Python memory allocations using the tracemalloc module.

The value of the variable is the maximum number of frames stored in a traceback of a trace. For example, PYTHONTRACEMALLOC=1 stores only the most recent frame.

  • PYTHONFAULTHANDLER โ€” If this environment variable is set to a non-empty string, faulthandler.enable() is called at startup: install a handler for SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL signals to dump the Python traceback.

This is equivalent to the -X faulthandler option.

  • PYTHONEXECUTABLE โ€” If this environment variable is set, sys.argv[0] will be set to its value instead of the value got through the C runtime. Only works on Mac OS X. ๐ŸŽ
  • PYTHONUSERBASE โ€” 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.
  • PYTHONPROFILEIMPORTTIME โ€” If this environment variable is set to a non-empty string, Python will show how long each import takes. This is exactly equivalent to setting -X importtime on the command line.
  • PYTHONBREAKPOINT โ€” If this environment variable is set to 0, it disables the default debugger. It can be set to the callable of your debugger of choice.

๐Ÿงš Debug-mode variables ๐Ÿงš

Setting these variables only has an effect in a debug build of Python, that is, if Python was configured with the --with-pydebug build option. (iykyk ๐Ÿ”ฅ)

  • PYTHONTHREADDEBUG โ€” If this environment variable is set, Python will print threading debug info. The feature is deprecated in Python 3.10 and will be removed in Python 3.12. ๐Ÿ˜ญ
  • PYTHONDUMPREFS โ€” If this environment variable is set, Python will dump objects and reference counts still alive after shutting down the interpreter.

๐Ÿ’œ AUTHOR ๐Ÿ’œ

The Python Software Foundation: https://www.python.org/psf/


๐ŸŒˆ INTERNET RESOURCES ๐ŸŒˆ


๐Ÿ“œ LICENSING ๐Ÿ“œ

Python is distributed under an Open Source license. See the file "LICENSE" in the Python source distribution for information on terms & conditions for accessing and otherwise using Python and for a DISCLAIMER OF ALL WARRANTIES. Read it fr fr, warranties are not it. ๐Ÿซถ


ok bestie that's the whole page ๐Ÿ’– it's from the PYTHON(1) manual, and it's dated โ€” slay, you made it all the way through, iconic behavior honestly. go write some Python. ๐Ÿ‘‘โœจ