PYTHON(1)

๐Ÿ“ฆ version 2.7.18, in ubuntu jammy

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

okay bestie, buckle up, because this is the page. the python one. the icon, the moment, the whole vibe. ๐Ÿ’…


โœจ NAME โœจ

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


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

python [ -B ] [ -d ] [ -E ] [ -h ] [ -i ] [ -m module-name ]
       [ -O ] [ -OO ] [ -R ] [ -Q argument ] [ -s ] [ -S ] [ -t ] [ -u ]
       [ -v ] [ -V ] [ -W argument ] [ -x ] [ -3 ] [ -?  ]
       [ -c command | script | - ] [ arguments ]

๐Ÿ’– DESCRIPTION ๐Ÿ’–

so. Python is an interpreted, interactive, object-oriented programming language that lowkey combines remarkable power with very clear syntax. it's giving "effortlessly powerful," no cap. โœจ

if you want an actual intro to programming in Python, go read the Python Tutorial. the Python Library Reference is where the built-in and standard types, constants, functions and modules are documented. and finally the Python Reference Manual describes the syntax and semantics of the core language in (perhaps too) much detail โ€” like, it truly said "I will explain everything." ๐Ÿ˜ญ you can find all these documents via the INTERNET RESOURCES below (and they might already be installed on your system too, check bestie).

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

and ooh, documentation for installed Python modules and packages can be viewed by running the pydoc program. iconic.


๐Ÿ‘‘ COMMAND LINE OPTIONS ๐Ÿ‘‘

  • -B โ€” don't write .py[co] files on import. see also PYTHONDONTWRITEBYTECODE. (no extra bytecode crumbs left behind, we love a clean room ๐Ÿ’…)
  • -c command โ€” specify the command to execute (peep the next section for the deets). this terminates the option list โ€” meaning everything after it gets passed as arguments to the command. periodt.
  • -d โ€” turn on parser debugging output. (for wizards only ๐Ÿ”ฎ, and it depends on compilation options.)
  • -E โ€” ignore environment variables like PYTHONPATH and PYTHONHOME that modify the behavior of the interpreter.
  • -h, -?, --help โ€” prints the usage for the interpreter executable and exits. the classic "help me" trio.
  • -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 is so useful for inspecting global variables or a stack trace when a script raises an exception โ€” like peeking behind the curtain after the drama. ๐Ÿ™ˆ
  • -m module-name โ€” searches sys.path for the named module and runs the corresponding .py file as a script.
  • -O โ€” turn on basic optimizations. this changes the filename extension for compiled (bytecode) files from .pyc to .pyo. given twice, it causes docstrings to be discarded. ๐Ÿ˜ญ (the docstrings!!)
  • -OO โ€” discard docstrings in addition to the -O optimizations.
  • -R โ€” turn on "hash randomization", so that the hash() values of str, bytes and datetime objects are "salted" with an unpredictable pseudo-random value. although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python.

this is intended to provide protection against a denial of service caused by carefully-chosen inputs that exploit the worst case performance of a dict construction, O(n^2) complexity. see http://www.ocert.org/advisories/ocert-2011-003.html for details.

  • -Q argument โ€” division control; see PEP 238. the argument must be one of:
    • "old" โ€” the default, int/int and long/long return an int or long
    • "new" โ€” new division semantics, i.e. int/int and long/long returns a float
    • "warn" โ€” old division semantics with a warning for int/int and long/long
    • "warnall" โ€” old division semantics with a warning for all use of the division operator

for a use of "warnall", see the Tools/scripts/fixdiv.py script.

  • -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.
  • -t โ€” issue a warning when a source file mixes tabs and spaces for indentation in a way that makes it depend on the worth of a tab expressed in spaces. issue an error when the option is given twice.
  • -u โ€” force stdin, stdout and stderr to be totally unbuffered. on systems where it matters, also put stdin, stdout and stderr in binary mode. note that there is internal buffering in xreadlines(), readlines() and file-object iterators ("for line in sys.stdin") which is not influenced by this option. to work around this, you will want to use "sys.stdin.readline()" inside a "while 1:" loop.
  • -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. (chatty king ๐Ÿ’ฌ)
  • -V, --version โ€” prints the Python version number of the executable and exits.
  • -W argument โ€” warning control. Python sometimes prints warning message to sys.stderr. a typical warning message has the following form: file:line: category: message. by default, each warning is printed once for each source line where it occurs. this option controls how often warnings are printed. multiple -W options may be given; when a warning matches more than one option, the action for the last matching option is performed. invalid -W options are ignored (a warning message is printed about invalid options when the first warning is issued). warnings can also be controlled from within a Python program using the warnings module.

the simplest form of argument is one of the following action strings (or a unique abbreviation):

  • ignore โ€” to ignore all warnings
  • default โ€” to explicitly request the default behavior (printing each warning once per source line)
  • all โ€” to print a warning each time it occurs (this may generate many messages if a warning is triggered repeatedly for the same source line, such as inside a loop)
  • module โ€” to print each warning only the first time it occurs in each module
  • once โ€” to print each warning only the first time it occurs in the program
  • error โ€” to raise an exception instead of printing a warning message

the full form of argument is action:message:category:module:line. here, action is as explained above but only applies to messages that match the remaining fields. empty fields match all values; trailing empty fields may be omitted. the message field matches the start of the warning message printed; this match is case-insensitive. the category field matches the warning category. 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 full class name must be given. the module field matches the (fully-qualified) module name; this match is case-sensitive. the line field matches the line number, where zero matches all line numbers and is thus equivalent to an omitted line number.

  • -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! โš ๏ธ
  • -3 โ€” warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.

๐ŸŒˆ INTERPRETER INTERFACE ๐ŸŒˆ

the interpreter interface resembles that of the UNIX shell, which is honestly such a serve. here's the tea:

  • when called with standard input connected to a tty device, it prompts for commands and executes them until an EOF is read;
  • when called with a file name argument or with a file as standard input, it reads and executes a script from that file;
  • when called with -c command, it executes the Python statement(s) given as command.

here, command may contain multiple statements separated by newlines. leading whitespace is significant in Python statements! 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 (you must first import sys to be able to access it). if no script name is given, sys.argv[0] is an empty string; if -c is 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 >>>; the second prompt (which appears when a command is not complete) is .... the prompts can be changed by assignment to sys.ps1 or sys.ps2. 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; ${prefix} and ${exec_prefix} are installation-dependent and should be interpreted as for GNU software; they may be the same. on Debian GNU/{Hurd,Linux} the default for both is /usr.

  • ${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.
  • ~/.pythonrc.py โ€” user-specific initialization file loaded by the user module; not used by default or by most applications. (it's the shy one, it only shows up if you invite it ๐Ÿซถ)

...and bestie, that's not even the whole page โ€” more parts are coming, so stay tuned ๐Ÿ’œ

๐ŸŒฟ ENVIRONMENT VARIABLES ๐ŸŒฟ

okay bestie, these are the little environment switches that change Python's whole personality before it even boots up. no cap, they're giving backstage pass energy. ๐Ÿ’…

PYTHONHOME

This one changes where the standard Python libraries live. by default, Python looks in ${prefix}/lib/python<version> and ${exec_prefix}/lib/python<version> โ€” and ${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}. wanna give them different values? set $PYTHONHOME to ${prefix}:${exec_prefix}. periodt. ๐Ÿ 

PYTHONPATH

This augments the default search path for module files. format? same as the shell's $PATH: one or more directory pathnames separated by colons. non-existent directories are silently ignored (so rude but okay). the default search path is installation dependent, but generally begins with ${prefix}/lib/python<version> (peep 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. you can also manipulate the search path from within a Python program as the variable sys.path. ๐Ÿ”

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 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. it's giving pre-game ritual. ๐ŸŽ€

PYTHONY2K

Set this to a non-empty string to cause the time module to require dates specified as strings to include 4-digit years. otherwise, 2-digit years are converted based on rules described in the time module documentation. y2k but make it Python. ๐Ÿ•ฐ๏ธ

PYTHONOPTIMIZE

If this is set to a non-empty string, it's equivalent to specifying the -O option. if set to an integer, it's equivalent to specifying -O multiple times. optimization queen. โœจ

PYTHONDEBUG

If this is set to a non-empty string, it's equivalent to specifying the -d option. if set to an integer, it's equivalent to specifying -d multiple times. debug mode activated, bestie. ๐Ÿ›

PYTHONDONTWRITEBYTECODE

If this is set to a non-empty string, it's equivalent to specifying the -B option (don't try to write .py[co] files). no bytecode leftovers, we love a clean girl. ๐Ÿงผ

PYTHONINSPECT

If this is set to a non-empty string, it's equivalent to specifying the -i option. inspect away. ๐Ÿ”Ž

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ยด. encoding drama handled. ๐Ÿ’–

PYTHONNOUSERSITE

If this is set to a non-empty string, it's equivalent to specifying the -s option (Don't add the user site directory to sys.path). no user site, just vibes. ๐Ÿšซ

PYTHONUNBUFFERED

If this is set to a non-empty string, it's equivalent to specifying the -u option. unbuffered and unbothered. ๐ŸŒŠ

PYTHONVERBOSE

If this is set to a non-empty string, it's equivalent to specifying the -v option. if set to an integer, it's equivalent to specifying -v multiple times. verbose? more like yappable. ๐Ÿ—ฃ๏ธ

PYTHONWARNINGS

If this is set to a comma-separated string, it's equivalent to specifying the -W option for each separate value. warnings but make it a whole list. โš ๏ธ

PYTHONHASHSEED

If this variable is set to "random", the effect is the same as specifying the -R option: a random value is used to seed the hashes of str, bytes and datetime objects.

If PYTHONHASHSEED is set to an integer value, it's 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 lead to the same hash values as when hash randomization is disabled. hash girl summer. ๐Ÿ”ข


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

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

they literally made Python. legends only. ๐Ÿซถ


๐ŸŒ INTERNET RESOURCES ๐ŸŒ

go touch some docs, bestie. ๐Ÿ“šโœจ


๐Ÿ“œ 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.

tl;dr: open source, but read the LICENSE for the legal tea. ๐Ÿต

That's the whole PYTHON(1) manual, bestie โ€” source/version/date are in the footer, and they're iconic. This was the Python 2.7-era manpage (peep the python2.7 docs path), and the footer said PYTHON(1). slay, you made it to the end. ๐Ÿ’…๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from