blob: 9f71d69dfaf260ea8eedff6c443ba755b91a276c [file] [log] [blame]
Benjamin Petersonb9869df2016-03-21 22:31:02 -07001.TH PYTHON "1"
Andrew M. Kuchling3afe4f32004-10-07 12:30:54 +00002
Benjamin Peterson5f28b7b2009-03-26 21:49:58 +00003.\" To view this file while editing, run it through groff:
4.\" groff -Tascii -man python.man | less
Andrew M. Kuchling3afe4f32004-10-07 12:30:54 +00005
Guido van Rossuma7925f11994-01-26 10:20:16 +00006.SH NAME
7python \- an interpreted, interactive, object-oriented programming language
8.SH SYNOPSIS
9.B python
10[
Matthias Klosec8b16f82010-01-31 16:14:37 +000011.B \-B
12]
13[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050014.B \-b
15]
16[
Guido van Rossuma7925f11994-01-26 10:20:16 +000017.B \-d
18]
19[
Guido van Rossumb674baf2001-09-05 18:55:34 +000020.B \-E
21]
22[
23.B \-h
24]
25[
Guido van Rossuma7925f11994-01-26 10:20:16 +000026.B \-i
27]
28[
Christian Heimesad73a9c2013-08-10 16:36:18 +020029.B \-I
Andrew M. Kuchling166e6252004-10-07 12:04:50 +000030]
Guido van Rossumb674baf2001-09-05 18:55:34 +000031.br
32 [
Christian Heimesad73a9c2013-08-10 16:36:18 +020033.B \-m
34.I module-name
35]
36[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050037.B \-q
38]
39[
Matthias Klosec8b16f82010-01-31 16:14:37 +000040.B \-O
41]
42[
R David Murray9c4f09d2011-05-01 11:13:56 -040043.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +000044]
45[
Matthias Klosec8b16f82010-01-31 16:14:37 +000046.B \-s
47]
48[
Guido van Rossumb674baf2001-09-05 18:55:34 +000049.B \-S
Neil Schemenauer7d4bb9f2001-07-23 16:30:27 +000050]
51[
Guido van Rossumef5bca31994-05-03 14:15:32 +000052.B \-u
Guido van Rossuma7925f11994-01-26 10:20:16 +000053]
Guido van Rossumb674baf2001-09-05 18:55:34 +000054.br
55 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000056.B \-v
57]
Guido van Rossum07c44c71998-04-10 19:46:00 +000058[
Barry Warsaw64569372000-09-15 18:39:09 +000059.B \-V
60]
Guido van Rossum1378c322000-12-19 03:21:54 +000061[
62.B \-W
63.I argument
64]
Guido van Rossumb674baf2001-09-05 18:55:34 +000065[
66.B \-x
67]
Matthias Klosec8b16f82010-01-31 16:14:37 +000068[
Senthil Kumarance3dd0b2013-06-19 22:19:46 -050069[
70.B \-X
71.I option
72]
Matthias Klosec8b16f82010-01-31 16:14:37 +000073.B \-?
74]
Guido van Rossum4cf4de51997-09-08 04:06:15 +000075.br
76 [
Guido van Rossuma7925f11994-01-26 10:20:16 +000077.B \-c
78.I command
79|
80.I script
81|
82\-
83]
84[
85.I arguments
86]
87.SH DESCRIPTION
88Python is an interpreted, interactive, object-oriented programming
89language that combines remarkable power with very clear syntax.
Benjamin Petersonb0335ee2015-04-29 18:00:44 -040090For an introduction to programming in Python, see the Python Tutorial.
Guido van Rossuma7925f11994-01-26 10:20:16 +000091The Python Library Reference documents built-in and standard types,
92constants, functions and modules.
93Finally, the Python Reference Manual describes the syntax and
94semantics of the core language in (perhaps too) much detail.
Guido van Rossumf4a090d2000-09-01 20:36:34 +000095(These documents may be located via the
96.B "INTERNET RESOURCES"
Fred Drake4c9be9d1999-08-20 13:10:20 +000097below; they may be installed on your system as well.)
Guido van Rossuma7925f11994-01-26 10:20:16 +000098.PP
99Python's basic power can be extended with your own modules written in
100C or C++.
Guido van Rossum74faed21996-07-30 19:27:05 +0000101On most systems such modules may be dynamically loaded.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000102Python is also adaptable as an extension language for existing
103applications.
104See the internal documentation for hints.
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000105.PP
Brett Cannonf299abd2015-04-13 14:21:02 -0400106Documentation for installed Python modules and packages can be
107viewed by running the
Andrew M. Kuchling88717f42001-04-05 14:50:40 +0000108.B pydoc
Brett Cannonf299abd2015-04-13 14:21:02 -0400109program.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000110.SH COMMAND LINE OPTIONS
111.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000112.B \-B
113Don't write
Brett Cannon10a7dbd2016-10-21 12:15:14 -0700114.I .pyc
Matthias Klosec8b16f82010-01-31 16:14:37 +0000115files on import. See also PYTHONDONTWRITEBYTECODE.
116.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500117.B \-b
118Issue warnings about str(bytes_instance), str(bytearray_instance)
119and comparing bytes/bytearray with str. (-bb: issue errors)
120.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000121.BI "\-c " command
122Specify the command to execute (see next section).
123This terminates the option list (following options are passed as
124arguments to the command).
125.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000126.B \-d
127Turn on parser debugging output (for wizards only, depending on
128compilation options).
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000129.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000130.B \-E
131Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
132the behavior of the interpreter.
133.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000134.B \-h ", " \-? ", "\-\-help
Guido van Rossumb674baf2001-09-05 18:55:34 +0000135Prints the usage for the interpreter executable and exits.
136.TP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000137.B \-i
138When a script is passed as first argument or the \fB\-c\fP option is
139used, enter interactive mode after executing the script or the
Guido van Rossum9f65ae01994-02-23 09:10:27 +0000140command. It does not read the $PYTHONSTARTUP file. This can be
141useful to inspect global variables or a stack trace when a script
142raises an exception.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000143.TP
Christian Heimesad73a9c2013-08-10 16:36:18 +0200144.B \-I
Ned Deily64298ae2015-04-29 14:51:43 -0700145Run Python in isolated mode. This also implies \fB\-E\fP and \fB\-s\fP. In
Serhiy Storchaka225821c2015-12-18 13:05:04 +0200146isolated mode sys.path contains neither the script's directory nor the user's
Christian Heimesad73a9c2013-08-10 16:36:18 +0200147site-packages directory. All PYTHON* environment variables are ignored, too.
148Further restrictions may be imposed to prevent the user from injecting
149malicious code.
150.TP
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000151.BI "\-m " module-name
Brett Cannonf299abd2015-04-13 14:21:02 -0400152Searches
153.I sys.path
154for the named module and runs the corresponding
155.I .py
Andrew M. Kuchling166e6252004-10-07 12:04:50 +0000156file as a script.
157.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000158.B \-O
Brett Cannonf299abd2015-04-13 14:21:02 -0400159Turn on basic optimizations. Given twice, causes docstrings to be discarded.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000160.TP
R David Murray9c4f09d2011-05-01 11:13:56 -0400161.B \-OO
Matthias Klosec8b16f82010-01-31 16:14:37 +0000162Discard docstrings in addition to the \fB-O\fP optimizations.
163.TP
Georg Brandl9d871192010-12-04 10:47:18 +0000164.B \-q
Brett Cannonf299abd2015-04-13 14:21:02 -0400165Do not print the version and copyright messages. These messages are
Georg Brandl9d871192010-12-04 10:47:18 +0000166also suppressed in non-interactive mode.
167.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000168.B \-s
169Don't add user site directory to sys.path.
170.TP
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000171.B \-S
172Disable the import of the module
173.I site
174and the site-dependent manipulations of
175.I sys.path
Éric Araujoc09fca62011-03-23 02:06:24 +0100176that it entails. Also disable these manipulations if
177.I site
178is explicitly imported later.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000179.TP
Guido van Rossumef5bca31994-05-03 14:15:32 +0000180.B \-u
Berker Peksag7f580972017-10-13 15:16:31 +0300181Force the stdout and stderr streams to be unbuffered.
182This option has no effect on the stdin stream.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000183.TP
184.B \-v
185Print a message each time a module is initialized, showing the place
Fred Drake4c9be9d1999-08-20 13:10:20 +0000186(filename or built-in module) from which it is loaded. When given
Brett Cannonf299abd2015-04-13 14:21:02 -0400187twice, print a message for each file that is checked for when
Fred Drake4c9be9d1999-08-20 13:10:20 +0000188searching for a module. Also provides information on module cleanup
189at exit.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000190.TP
Matthias Klosec8b16f82010-01-31 16:14:37 +0000191.B \-V ", " \-\-version
INADA Naoki0e175a62016-11-21 20:57:14 +0900192Prints the Python version number of the executable and exits. When given
193twice, print more information about the build.
Barry Warsaw64569372000-09-15 18:39:09 +0000194.TP
Guido van Rossum1378c322000-12-19 03:21:54 +0000195.BI "\-W " argument
196Warning control. Python sometimes prints warning message to
197.IR sys.stderr .
198A typical warning message has the following form:
199.IB file ":" line ": " category ": " message.
200By default, each warning is printed once for each source line where it
201occurs. This option controls how often warnings are printed.
202Multiple
203.B \-W
204options may be given; when a warning matches more than one
205option, the action for the last matching option is performed.
206Invalid
207.B \-W
208options are ignored (a warning message is printed about invalid
209options when the first warning is issued). Warnings can also be
210controlled from within a Python program using the
211.I warnings
212module.
213
214The simplest form of
215.I argument
216is one of the following
217.I action
218strings (or a unique abbreviation):
219.B ignore
220to ignore all warnings;
221.B default
222to explicitly request the default behavior (printing each warning once
223per source line);
224.B all
225to print a warning each time it occurs (this may generate many
226messages if a warning is triggered repeatedly for the same source
Fred Drakebd2e3b02001-07-26 21:25:58 +0000227line, such as inside a loop);
Guido van Rossum1378c322000-12-19 03:21:54 +0000228.B module
Georg Brandleeb575f2009-06-24 06:42:05 +0000229to print each warning only the first time it occurs in each
Guido van Rossum1378c322000-12-19 03:21:54 +0000230module;
231.B once
232to print each warning only the first time it occurs in the program; or
233.B error
234to raise an exception instead of printing a warning message.
235
236The full form of
237.I argument
238is
239.IB action : message : category : module : line.
240Here,
241.I action
242is as explained above but only applies to messages that match the
243remaining fields. Empty fields match all values; trailing empty
244fields may be omitted. The
245.I message
246field matches the start of the warning message printed; this match is
247case-insensitive. The
248.I category
249field matches the warning category. This must be a class name; the
250match test whether the actual warning category of the message is a
251subclass of the specified warning category. The full class name must
252be given. The
253.I module
254field matches the (fully-qualified) module name; this match is
255case-sensitive. The
256.I line
257field matches the line number, where zero matches all line numbers and
258is thus equivalent to an omitted line number.
259.TP
Senthil Kumarance3dd0b2013-06-19 22:19:46 -0500260.BI "\-X " option
261Set implementation specific option.
262.TP
Guido van Rossumb674baf2001-09-05 18:55:34 +0000263.B \-x
264Skip the first line of the source. This is intended for a DOS
265specific hack only. Warning: the line numbers in error messages will
266be off by one!
Guido van Rossuma7925f11994-01-26 10:20:16 +0000267.SH INTERPRETER INTERFACE
268The interpreter interface resembles that of the UNIX shell: when
269called with standard input connected to a tty device, it prompts for
270commands and executes them until an EOF is read; when called with a
271file name argument or with a file as standard input, it reads and
272executes a
273.I script
274from that file;
275when called with
276.B \-c
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200277.IR command ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000278it executes the Python statement(s) given as
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200279.IR command .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000280Here
281.I command
282may contain multiple statements separated by newlines.
283Leading whitespace is significant in Python statements!
Matthias Klose31a58df2005-03-20 14:16:03 +0000284In non-interactive mode, the entire input is parsed before it is
Guido van Rossuma7925f11994-01-26 10:20:16 +0000285executed.
286.PP
287If available, the script name and additional arguments thereafter are
288passed to the script in the Python variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200289.IR sys.argv ,
Guido van Rossuma7925f11994-01-26 10:20:16 +0000290which is a list of strings (you must first
291.I import sys
292to be able to access it).
293If no script name is given,
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000294.I sys.argv[0]
295is an empty string; if
Guido van Rossuma7925f11994-01-26 10:20:16 +0000296.B \-c
297is used,
298.I sys.argv[0]
299contains the string
300.I '-c'.
Guido van Rossum74faed21996-07-30 19:27:05 +0000301Note that options interpreted by the Python interpreter itself
Guido van Rossuma7925f11994-01-26 10:20:16 +0000302are not placed in
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200303.IR sys.argv .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000304.PP
305In interactive mode, the primary prompt is `>>>'; the second prompt
306(which appears when a command is not complete) is `...'.
307The prompts can be changed by assignment to
308.I sys.ps1
309or
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200310.IR sys.ps2 .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000311The interpreter quits when it reads an EOF at a prompt.
312When an unhandled exception occurs, a stack trace is printed and
313control returns to the primary prompt; in non-interactive mode, the
314interpreter exits after printing the stack trace.
315The interrupt signal raises the
316.I Keyboard\%Interrupt
317exception; other UNIX signals are not caught (except that SIGPIPE is
318sometimes ignored, in favor of the
319.I IOError
320exception). Error messages are written to stderr.
321.SH FILES AND DIRECTORIES
322These are subject to difference depending on local installation
Fred Drake4c9be9d1999-08-20 13:10:20 +0000323conventions; ${prefix} and ${exec_prefix} are installation-dependent
324and should be interpreted as for GNU software; they may be the same.
325The default for both is \fI/usr/local\fP.
326.IP \fI${exec_prefix}/bin/python\fP
Guido van Rossuma7925f11994-01-26 10:20:16 +0000327Recommended location of the interpreter.
Fred Drake4c9be9d1999-08-20 13:10:20 +0000328.PP
329.I ${prefix}/lib/python<version>
330.br
331.I ${exec_prefix}/lib/python<version>
332.RS
333Recommended locations of the directories containing the standard
334modules.
335.RE
336.PP
337.I ${prefix}/include/python<version>
338.br
339.I ${exec_prefix}/include/python<version>
340.RS
341Recommended locations of the directories containing the include files
342needed for developing Python extensions and embedding the
343interpreter.
344.RE
Guido van Rossuma7925f11994-01-26 10:20:16 +0000345.SH ENVIRONMENT VARIABLES
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000346.IP PYTHONHOME
347Change the location of the standard Python libraries. By default, the
Fred Drake4c9be9d1999-08-20 13:10:20 +0000348libraries are searched in ${prefix}/lib/python<version> and
349${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000350are installation-dependent directories, both defaulting to
Fred Drake4c9be9d1999-08-20 13:10:20 +0000351\fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
352replaces both ${prefix} and ${exec_prefix}. To specify different values
353for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000354.IP PYTHONPATH
355Augments the default search path for module files.
356The format is the same as the shell's $PATH: one or more directory
357pathnames separated by colons.
Matthias Klose31a58df2005-03-20 14:16:03 +0000358Non-existent directories are silently ignored.
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000359The default search path is installation dependent, but generally
Fred Drake4c9be9d1999-08-20 13:10:20 +0000360begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
Guido van Rossum4cf4de51997-09-08 04:06:15 +0000361The default search path is always appended to $PYTHONPATH.
Guido van Rossum74faed21996-07-30 19:27:05 +0000362If a script argument is given, the directory containing the script is
363inserted in the path in front of $PYTHONPATH.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000364The search path can be manipulated from within a Python program as the
365variable
doko@ubuntu.comd8623e82012-06-20 13:16:31 +0200366.IR sys.path .
Guido van Rossuma7925f11994-01-26 10:20:16 +0000367.IP PYTHONSTARTUP
368If this is the name of a readable file, the Python commands in that
369file are executed before the first prompt is displayed in interactive
370mode.
371The file is executed in the same name space where interactive commands
372are executed so that objects defined or imported in it can be used
373without qualification in the interactive session.
374You can also change the prompts
375.I sys.ps1
376and
377.I sys.ps2
378in this file.
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000379.IP PYTHONOPTIMIZE
380If this is set to a non-empty string it is equivalent to specifying
381the \fB\-O\fP option. If set to an integer, it is equivalent to
382specifying \fB\-O\fP multiple times.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000383.IP PYTHONDEBUG
384If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000385the \fB\-d\fP option. If set to an integer, it is equivalent to
386specifying \fB\-d\fP multiple times.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000387.IP PYTHONDONTWRITEBYTECODE
388If this is set to a non-empty string it is equivalent to specifying
389the \fB\-B\fP option (don't try to write
Brett Cannon10a7dbd2016-10-21 12:15:14 -0700390.I .pyc
Matthias Klosec8b16f82010-01-31 16:14:37 +0000391files).
Guido van Rossuma7925f11994-01-26 10:20:16 +0000392.IP PYTHONINSPECT
393If this is set to a non-empty string it is equivalent to specifying
394the \fB\-i\fP option.
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000395.IP PYTHONIOENCODING
396If this is set before running the interpreter, it overrides the encoding used
397for stdin/stdout/stderr, in the syntax
398.IB encodingname ":" errorhandler
399The
400.IB errorhandler
401part is optional and has the same meaning as in str.encode. For stderr, the
402.IB errorhandler
403 part is ignored; the handler will always be \'backslashreplace\'.
Matthias Klosec8b16f82010-01-31 16:14:37 +0000404.IP PYTHONNOUSERSITE
Benjamin Petersonee85a1d2010-10-13 22:20:15 +0000405If this is set to a non-empty string it is equivalent to specifying the
406\fB\-s\fP option (Don't add the user site directory to sys.path).
Guido van Rossumef5bca31994-05-03 14:15:32 +0000407.IP PYTHONUNBUFFERED
Guido van Rossuma7925f11994-01-26 10:20:16 +0000408If this is set to a non-empty string it is equivalent to specifying
Guido van Rossumef5bca31994-05-03 14:15:32 +0000409the \fB\-u\fP option.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000410.IP PYTHONVERBOSE
411If this is set to a non-empty string it is equivalent to specifying
Guido van Rossum9abaf4d2001-10-12 22:17:56 +0000412the \fB\-v\fP option. If set to an integer, it is equivalent to
Brett Cannonf299abd2015-04-13 14:21:02 -0400413specifying \fB\-v\fP multiple times.
Philip Jenvey0805ca32010-04-07 04:04:10 +0000414.IP PYTHONWARNINGS
415If this is set to a comma-separated string it is equivalent to
416specifying the \fB\-W\fP option for each separate value.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100417.IP PYTHONHASHSEED
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500418If this variable is set to "random", a random value is used to seed the hashes
419of str, bytes and datetime objects.
Georg Brandl2daf6ae2012-02-20 19:54:16 +0100420
421If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
422generating the hash() of the types covered by the hash randomization. Its
423purpose is to allow repeatable hashing, such as for selftests for the
424interpreter itself, or to allow a cluster of python processes to share hash
425values.
426
427The integer must be a decimal number in the range [0,4294967295]. Specifying
Benjamin Petersonc9f54cf2012-02-21 16:08:05 -0500428the value 0 will disable hash randomization.
Guido van Rossuma7925f11994-01-26 10:20:16 +0000429.SH AUTHOR
Benjamin Peterson37c4f782015-05-10 21:19:18 -0400430The Python Software Foundation: https://www.python.org/psf/
Guido van Rossum74faed21996-07-30 19:27:05 +0000431.SH INTERNET RESOURCES
Benjamin Peterson755640b2015-04-30 17:37:11 -0400432Main website: https://www.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000433.br
Benjamin Peterson755640b2015-04-30 17:37:11 -0400434Documentation: https://docs.python.org/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000435.br
Lisa Hewus Fresh384899d2017-08-30 09:37:43 -0700436Developer resources: https://devguide.python.org/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000437.br
Benjamin Peterson755640b2015-04-30 17:37:11 -0400438Downloads: https://www.python.org/downloads/
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000439.br
Benjamin Peterson755640b2015-04-30 17:37:11 -0400440Module repository: https://pypi.python.org/
Guido van Rossum74faed21996-07-30 19:27:05 +0000441.br
Fred Drakebd2e3b02001-07-26 21:25:58 +0000442Newsgroups: comp.lang.python, comp.lang.python.announce
Guido van Rossumf4a090d2000-09-01 20:36:34 +0000443.SH LICENSING
444Python is distributed under an Open Source license. See the file
445"LICENSE" in the Python source distribution for information on terms &
446conditions for accessing and otherwise using Python and for a
447DISCLAIMER OF ALL WARRANTIES.