PYTHON(1)
πΈ PYTHON πΈ
okay bestie, so this is the python page from the General Commands Manual β yes, THAT python. the interpreted, interactive, object-oriented programming language one. the moment has arrived π
β¨ NAME β¨
python β an interpreted, interactive, object-oriented programming language ππ
π SYNOPSIS π
python [ -B ] [ -b ] [ -d ] [ -E ] [ -h ] [ -i ] [ -I ]
[ -m module-name ] [ -q ] [ -O ] [ -OO ] [ -s ] [ -S ] [ -u ]
[ -v ] [ -V ] [ -W argument ] [ -x ] [ -X option ] [ -? ]
[ --check-hash-based-pycs default | always | never ]
[ -c command | script | - ] [ arguments ]
π¦ DESCRIPTION π¦
Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax. literally iconic behaviour. π
If you're new and wanna actually learn to write Python, go read the Python Tutorial. The Python Library Reference is where all the built-in and standard types, constants, functions and modules live. And then the Python Reference Manual explains the syntax and semantics of the core language in β and I quote β "(perhaps too) much detail" π. All of these may be located via the INTERNET RESOURCES below, and they might be installed on your system too, so check bestie.
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, iykyk.
And ngl, you can view documentation for installed Python modules and packages by running the pydoc program. no cap. π
π COMMAND LINE OPTIONS π
okay so this is the long part. buckle up. every flag, every vibe, let's gooo β¨
-Bβ don't write.pycfiles on import. see alsoPYTHONDONTWRITEBYTECODE. it's giving "no thank you to the bytecode" π-bβ issue warnings aboutstr(bytes_instance),str(bytearray_instance)and comparingbytes/bytearraywithstr. (-bb: issue errors β so like, extra spicy mode πΆοΈ)-c commandβ specify the command to execute (see next section). this terminates the option list, meaning everything after it gets passed as arguments to the command. noted π--check-hash-based-pycs modeβ configure how Python evaluates the up-to-dateness of hash-based.pycfiles. the modes aredefault,always,never, per the synopsis β¨-dβ turn on parser debugging output (for experts only, and it depends on compilation options). main character energy, but only if you're built for it π-Eβ ignore environment variables likePYTHONPATHandPYTHONHOMEthat modify the behavior of the interpreter. no outside influence, we're independent π¦-h,-?,--helpβ prints the usage for the interpreter executable and exits. your bestie when you're lost π«Ά-iβ when a script is passed as first argument or the-coption is used, enter interactive mode after executing the script or the command. it does not read the$PYTHONSTARTUPfile. this is lowkey so useful for inspecting global variables or a stack trace when a script raises an exception π₯-Iβ run Python in isolated mode. this also implies-Eand-s. in isolated modesys.pathcontains neither the script's directory nor the user'ssite-packagesdirectory. allPYTHON*environment variables are ignored too. further restrictions may be imposed to prevent the user from injecting malicious code. it's giving locked-down, protected, unbothered π-m module-nameβ searchessys.pathfor the named module and runs the corresponding.pyfile as a script. this terminates the option list (following options are passed as arguments to the module). so put your module first, bestie π-Oβ removeassertstatements and any code conditional on the value of__debug__; augment the filename for compiled (bytecode) files by adding.opt-1before the.pycextension π§-OOβ do-Oand also discard docstrings; change the filename for compiled (bytecode) files by adding.opt-2before the.pycextension. double optimized, double slay β¨-qβ do not print the version and copyright messages. these messages are also suppressed in non-interactive mode. quiet luxury, we love her π€«-sβ don't add user site directory tosys.pathπ«-Sβ disable the import of the modulesiteand the site-dependent manipulations ofsys.paththat it entails. also disable these manipulations ifsiteis explicitly imported later. so it stays off even if you come back for it π-uβ force thestdoutandstderrstreams to be unbuffered. this option has no effect on thestdinstream. important!! βοΈ-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. it's giving investigative journalist π-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 tosys.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. β¨
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. iconique π
-X optionβ set 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 ofNFRAMEframes π-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 ispython3 -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
faulthandlermodule to dump the Python traceback on a crash - Enable
asynciodebug 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 int_max_str_digits=number: limit the size ofint<->strconversions. this helps avoid denial of service attacks when parsing untrusted data. the default issys.int_info.default_max_str_digits.0disables. π‘οΈ
-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! π
okay that's the whole options section, we ate that fr fr π½οΈβ¨ and bestie... there's still more coming. don't go anywhere π
π INTERPRETER INTERFACE π
okay bestie so the interpreter interface is literally giving UNIX shell energy. here's the tea on how it behaves depending on how you call it:
- call it with standard input hooked up to a tty device β it prompts you for commands and keeps executing them until it reads an EOF π
- call it with a file name argument, or with a file as standard input β it reads and executes a script from that file
- call it with
-c commandβ it executes the Python statement(s) you handed it ascommand
and just so you know, command can hold multiple statements separated by newlines. Leading whitespace is significant in Python statements! like, do not touch it, fr fr. and in non-interactive mode, the whole entire input gets parsed before any of it is executed. no cap.
if available, the script name and any additional arguments after it get passed to the script through the Python variable sys.argv, which is a list of strings (and yes you must import sys first to be able to access it, obviously π«Ά). if no script name is given, sys.argv[0] is an empty string; if -c is used, sys.argv[0] holds the string '-c'. also note that options interpreted by the Python interpreter itself are not placed in sys.argv. they're just not invited to that party π
in interactive mode, the primary prompt is >>>; the second prompt (which shows up when a command isn't complete yet) is .... you can change the prompts by assigning to sys.ps1 or sys.ps2. 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; 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 go to stderr, always.
π 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β the recommended location of the interpreter. this is where the icon lives π${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 you need for developing Python extensions and for embedding the interpreter.
πΈ ENVIRONMENT VARIABLES πΈ
the vibe check your shell passes down to Python. so many of them, and every single one matters.
PYTHONHOMEβ changes 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 (they don't get a warning, they just get ghosted π). 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. and you can manipulate the search path from within a Python program as the variablesys.path. slay.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. it's giving pre-game ritual β¨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. theerrorhandlerpart is optional and has the same meaning as instr.encode. for stderr, theerrorhandlerpart 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.
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 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 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 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. so like, don't count on it in those cases π
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=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 forSIGSEGV,SIGFPE,SIGABRT,SIGBUSandSIGILLsignals 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. (mac girlies stay winning π)PYTHONUSERBASEβ defines the user base directory, which is used to compute the path of the usersite-packagesdirectory and Distutils installation paths forpython 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 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. if you're not on a debug build, they're literally just vibes, nothing happens.
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. so, like, it's on its way out, bestie, don't build your whole personality on it.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/ β absolute icons, fr fr.
π 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
go touch some grass and then come back and read all of these, iykyk π
π 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. yes, all of them. every single warranty. gone. π
and that's the whole page bestie π«Ά this was the PYTHON(1) manual page, and the footer says it's from the Python source/version with its own date down at the bottom β you know the drill, check your local copy for the exact ones since that's where the version and date live. go forth and write some iconic code, main character. π
β¨
π¦ where this page comes from
- fedora 43: python3.10 3.10.18-2.fc43 Β· Python-2.0.1
- fedora 43: python3.10 3.10.18-2.fc43 Β· Python-2.0.1
- fedora 43: python3.10 3.10.22-1.fc43 Β· Python-2.0.1
- fedora 43: python3.10 3.10.22-1.fc43 Β· Python-2.0.1
- fedora 44: python3.10 3.10.20-1.fc44 Β· Python-2.0.1
- fedora 44: python3.10 3.10.20-1.fc44 Β· Python-2.0.1
- fedora 44: python3.10 3.10.22-1.fc44 Β· Python-2.0.1
- fedora 44: python3.10 3.10.22-1.fc44 Β· Python-2.0.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms