PYTHON(1)
๐ PYTHON(1) โ General Commands Manual
okay bestie, gather round, because we are about to get into python โ the General Commands Manual girlie, section 1, the one and only. this is the interpreter that runs your whole life and honestly? she ate. โจ
๐ NAME
python โ an interpreted, interactive, object-oriented programming language ๐๐
no cap, that's the whole vibe: interpreted, interactive, object-oriented. three personality traits, all iconic.
โจ 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 ]
like, look at all those little flags. it's giving options menu at a fancy restaurant ๐
๐ฆ DESCRIPTION
okay so. Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax. like, that's the actual sentence and it's so real โ she's powerful AND she communicates. main character energy fr fr. ๐
want an intro to programming in Python? go read the Python Tutorial. need the built-ins and the standard types, constants, functions and modules documented? that's the Python Library Reference. and if you want the syntax and semantics of the core language explained in (perhaps too) much detail โ their words, not mine, and honestly the shade is valid โ that's the Python Reference Manual.
those documents may be located via the INTERNET RESOURCES below, and they may also be installed on your system as well. check both, bestie, they're probably just sitting there. ๐
Python's basic power can be extended with your own modules written in C or C++. on most systems, such modules may be dynamically loaded. Python is also adaptable as an extension language for existing applications. see the internal documentation for hints. ๐ง
and if you ever wanna peek at the docs for the Python modules and packages you've got installed? just run the pydoc program. that's it. that's the plug. ๐
not me ending part 1 here like a cliffhanger bestie, but the page is LONG and there's more coming โ stay tuned, we're not done with her yet ๐ซถ
๐ COMMAND LINE OPTIONS ๐
okay bestie, this is the good part. these are the little letters you sprinkle after python3 to make it do your bidding. let's go one by one, no skips, periodt.
-Bโ don't write.pycfiles on import. that's it, that's the whole vibe. also peepPYTHONDONTWRITEBYTECODEif you're into that.-bโ throw warnings aboutstr(bytes_instance),str(bytearray_instance), and about comparing bytes/bytearray with str. and if you go-bb(double it up, slay) those become errors instead. ๐-c commandโ tell Python which command to execute (the next section spills the tea on this one). heads up: this terminates the option list, so anything after it gets passed as arguments to the command. bye options, hello args.--check-hash-based-pycs modeโ this one configures how Python decides whether a hash-based.pycfile is up to date. yes it's niche. yes it's iconic.-dโ turn on parser debugging output. expert only, and it depends on how your build was compiled. iykyk.-Eโ ignore environment variables likePYTHONPATHandPYTHONHOMEthat mess with how the interpreter behaves. it's giving "i don't see your env vars, bestie".-h,-?,--helpโ prints the usage for the interpreter executable and dips. classic.--help-envโ prints help about Python-specific environment variables, then exits. so handy fr fr.--help-xoptionsโ prints help about implementation-specific-Xoptions, then exits. โจ--help-allโ prints complete usage information and exits. the whole buffet.-iโ when a script is passed as the first argument, or when you use-c, this drops you into interactive mode after running the script or command. note: it does not read the$PYTHONSTARTUPfile. super useful for poking at global variables or grabbing a stack trace when a script raises an exception. ๐-Iโ run Python in isolated mode. this also implies-E,-Pand-s. in isolated mode,sys.pathcontains neither the script's directory nor the user's site-packages directory. allPYTHON*environment variables get ignored too. and further restrictions may be imposed to stop the user from injecting malicious code. safety first, babe. ๐ซถ-m module-nameโ searchessys.pathfor the named module and runs the corresponding.pyfile as a script. this terminates the option list (so everything after gets passed as arguments to the module).-Oโ removesassertstatements and any code conditional on the value of__debug__. it also augments the filename for compiled (bytecode) files by adding.opt-1before the.pycextension.-OOโ does everything-Odoes and throws away docstrings. it changes the compiled (bytecode) filename by adding.opt-2before the.pycextension. bye docstrings, we hardly knew ye. ๐ญ-Pโ don't automatically prepend a potentially unsafe path tosys.path, like the current directory, the script's directory, or an empty string. see also thePYTHONSAFEPATHenvironment variable.-qโ don't print the version and copyright messages. (these are also suppressed in non-interactive mode anyway.)-sโ don't add the user site directory tosys.path. not today, user site directory.-Sโ disable the import of the modulesiteand the site-dependent manipulations ofsys.paththat come with it. also disables those manipulations ifsitegets explicitly imported later. so it stays off, fr.-uโ force thestdoutandstderrstreams to be unbuffered. this option has no effect on thestdinstream. ๐-vโ print a message each time a module is initialized, showing the place (filename or built-in module) it's loaded from. give it twice and it prints a message for each file that gets checked while searching for a module. it also gives you info on module cleanup at exit. very chatty, very main character.-V,--versionโ prints the Python version number of the executable and exits. give it twice and it prints more information about the build.-W argumentโ warning control, babe. Python's warning machinery by default prints warning messages tosys.stderr.
the simplest settings apply a particular action unconditionally to all warnings emitted by a process (even the ones that are otherwise ignored by default):
-Wdefault # Warn once per call location
-Werror # Convert to exceptions
-Walways # Warn every time
-Wall # Same as -Walways
-Wmodule # Warn once per calling module
-Wonce # Warn once per Python process
-Wignore # Never warn
the action names can be abbreviated however you want and the interpreter will resolve them to the appropriate action name. for example, -Wi is the same as -Wignore.
the full form of argument is:
action:message:category:module:lineno
empty fields match all values, and trailing empty fields may be omitted. for example, -W ignore::DeprecationWarning ignores all DeprecationWarning warnings.
the action field is as explained above, but it 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 tests 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 apply a regular expression to the warning message.
-X optionโ set an implementation-specific option. the following options are available:-X faulthandlerโ enablefaulthandler.-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 thetracemallocmodule. by default, only the most recent frame is stored in a traceback of a trace. use-X tracemalloc=NFRAMEto start tracing with a traceback limit of NFRAME frames.-X importtimeโ show how long each import takes. it shows the module name, cumulative time (including nested imports) and self time (excluding nested imports). note that its output may be broken in multi-threaded applications. typical usage ispython3 -X importtime -c 'import asyncio'.-X devโ enable CPython's "development mode", introducing additional runtime checks that 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. the effect of developer mode is:- add default warning filter, as
-W default - install debug hooks on memory allocators: see the
PyMem_SetupDebugHooks()C function - enable the
faulthandlermodule to dump the Python traceback on a crash - enable asyncio debug mode
- set the
dev_modeattribute ofsys.flagstoTrue io.IOBasedestructor logsclose()exceptions
- add default warning filter, as
-X utf8โ enable UTF-8 mode for operating system interfaces, overriding the default locale-aware mode.-X utf8=0explicitly disables UTF-8 mode (even when it would otherwise activate automatically). seePYTHONUTF8for more details.-X pycache_prefix=PATHโ enable writing.pycfiles to a parallel tree rooted at the given directory instead of to the code tree.-X warn_default_encodingโ enable opt-inEncodingWarningfor'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 you want smaller code objects and pyc files, and it also suppresses 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 issys.int_info.default_max_str_digits.0disables it.
-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! ๐ญ
๐ธ INTERPRETER INTERFACE ๐ธ
okay so bestie, the interpreter interface is basically giving UNIX shell energy ๐ โ here's how it reads you:
- When it's called with standard input connected to a tty device, it prompts you for commands and executes them until it reads an EOF. Chatty queen behavior ๐ฌ
- When it's called with a file name argument or with a file as standard input, it reads and executes a script from that file ๐
- When it's called with
-ccommand, it executes the Python statement(s) given as command. And bestie, command can contain multiple statements separated by newlines. Leading whitespace is significant in Python statements! ๐ค like genuinely, don't touch the indentation. In non-interactive mode, the entire input is parsed before it is executed.
If available, the script name and additional arguments thereafter are passed to the script in the Python variable sys.argv, which is a list of strings โ and yes, you must first import sys to be able to access it, no cap ๐.
- If no script name is given,
sys.argv[0]is an empty string - If
-cis used,sys.argv[0]contains the string'-c' - Note that options interpreted by the Python interpreter itself are not placed in
sys.argv๐
In interactive mode, the primary prompt is >>> and the second prompt (the one that shows up when a command is not complete) is ... โจ. You can change the prompts by assignment to sys.ps1 or sys.ps2 โ customize your aesthetic, it's your right ๐.
The interpreter quits when it reads an EOF at a prompt. When an unhandled exception occurs, a stack trace is printed and control returns to the primary prompt ๐ซถ; in non-interactive mode, the interpreter 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, bestie โ ${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โ the 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 ๐
the way that these little guys control *everything*โฆ obsessed. iykyk ๐
PYTHONSAFEPATHโ if this is set to a non-empty string, don't automatically prepend a potentially unsafe path tosys.pathsuch as the current directory, the script's directory or an empty string. See also the-Poption. ๐ก๏ธ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$PYTHONHOMEis set to a single directory, its value replaces both${prefix}and${exec_prefix}. To specify different values for these, set$PYTHONHOMEto${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>(seePYTHONHOMEabove). 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 variablesys.path๐ฃ๏ธPYTHONPLATLIBDIRโ overridesys.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 promptssys.ps1andsys.ps2in this file ๐PYTHONOPTIMIZEโ if this is set to a non-empty string it is equivalent to specifying the-Ooption. If set to an integer, it is equivalent to specifying-Omultiple times โกPYTHONDEBUGโ if this is set to a non-empty string it is equivalent to specifying the-doption. If set to an integer, it is equivalent to specifying-dmultiple times ๐PYTHONDONTWRITEBYTECODEโ if this is set to a non-empty string it is equivalent to specifying the-Boption (don't try to write.pycfiles) ๐ซPYTHONINSPECTโ if this is set to a non-empty string it is equivalent to specifying the-ioption ๐PYTHONIOENCODINGโ if this is set before running the interpreter, it overrides the encoding used for stdin/stdout/stderr, in the syntaxencodingname:errorhandler. The errorhandler part is optional and has the same meaning as instr.encode. For stderr, the errorhandler part is ignored; the handler will always bebackslashreplaceโ๏ธPYTHONNOUSERSITEโ if this is set to a non-empty string it is equivalent to specifying the-soption (don't add the user site directory tosys.path) ๐PYTHONUNBUFFEREDโ if this is set to a non-empty string it is equivalent to specifying the-uoption ๐ฐPYTHONVERBOSEโ if this is set to a non-empty string it is equivalent to specifying the-voption. If set to an integer, it is equivalent to specifying-vmultiple times ๐ขPYTHONWARNINGSโ if this is set to a comma-separated string it is equivalent to specifying the-Woption for each separate value โ ๏ธPYTHONHASHSEEDโ if this variable is set to"random", a random value is used to seed the hashes ofstrandbytesobjects ๐ฒ IfPYTHONHASHSEEDis set to an integer value, it is used as a fixed seed for generating thehash()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 value0will disable hash randomization ๐PYTHONINTMAXSTRDIGITSโ limit the maximum digit characters in anintvalue when converting from a string and when converting anintback to astr. A value of0disables 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 aremallocandpymalloc. The available debug hooks aredebug,malloc_debug, andpymalloc_debug. When Python is compiled in debug mode, the default ispymalloc_debugand the debug hooks are automatically used. Otherwise, the default ispymalloc๐งPYTHONMALLOCSTATSโ if set to a non-empty string, Python will print statistics of thepymallocmemory allocator every time a newpymallocobject arena is created, and on shutdown ๐ This variable is ignored if the$PYTHONMALLOCenvironment variable is used to force themalloc(3)allocator of the C library, or if Python is configured withoutpymallocsupport ๐ซPYTHONASYNCIODEBUGโ if this environment variable is set to a non-empty string, enable the debug mode of theasynciomodule ๐PYTHONTRACEMALLOCโ if this environment variable is set to a non-empty string, start tracing Python memory allocations using thetracemallocmodule. The value of the variable is the maximum number of frames stored in a traceback of a trace. For example,PYTHONTRACEMALLOC=1stores 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 forSIGSEGV,SIGFPE,SIGABRT,SIGBUSandSIGILLsignals to dump the Python traceback. This is equivalent to the-X faulthandleroption ๐ฅ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 usersite-packagesdirectory and installation paths forpython -m pip 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 importtimeon the command line โฑ๏ธPYTHONBREAKPOINTโ if this environment variable is set to0, 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. so likeโฆ no debug build, no vibes ๐
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 ๐
- Main website:
https://www.python.org/ - Documentation:
https://docs.python.org/ - Developer resources:
https://devguide.python.org/ - Downloads:
https://www.python.org/downloads/ - Module repository:
https://pypi.org/ - Newsgroups:
comp.lang.python,comp.lang.python.announce๐ฐ
๐ 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 bestie, fr fr ๐
and that's a wrap on the whole page ๐ the footer says PYTHON(1) and that's the man page name your man command files it under โ slay, go forth and run some Python, you've got this ๐
โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.22: python3-doc 3.12.16-r0 ยท PSF-2.0
- alpine 3.23: python3-doc 3.12.16-r0 ยท PSF-2.0
- centos-stream 10: python3 3.12.15-1.el10 ยท Python-2.0.1
- centos-stream 9: python3.12 3.12.15-1.el9 ยท Python-2.0.1
- centos-stream 9: python3.12 3.12.15-1.el9 ยท Python-2.0.1
- fedora 43: python3.12 3.12.11-3.fc43 ยท Python-2.0.1
- fedora 43: python3.12 3.12.11-3.fc43 ยท Python-2.0.1
- fedora 43: python3.12 3.12.15-1.fc43 ยท Python-2.0.1
- fedora 43: python3.12 3.12.15-1.fc43 ยท Python-2.0.1
- fedora 44: python3.12 3.12.13-2.fc44 ยท Python-2.0.1
- fedora 44: python3.12 3.12.13-2.fc44 ยท Python-2.0.1
- fedora 44: python3.12 3.12.15-1.fc44
- fedora 44: python3.12 3.12.15-1.fc44
- fedora 44: python3.12 3.12.16-2.fc44 ยท Python-2.0.1
- fedora 44: python3.12 3.12.16-2.fc44 ยท Python-2.0.1
- nixpkgs unstable: libreoffice 26.2.5
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms