1PYTHON(1) General Commands Manual PYTHON(1)
2
3
4
6 python - an interpreted, interactive, object-oriented programming lan‐
7 guage
8
10 python [ -B ] [ -d ] [ -E ] [ -h ] [ -i ] [ -m module-name ]
11 [ -O ] [ -OO ] [ -R ] [ -Q argument ] [ -s ] [ -S ] [ -t ] [ -u
12 ]
13 [ -v ] [ -V ] [ -W argument ] [ -x ] [ -3 ] [ -? ]
14 [ -c command | script | - ] [ arguments ]
15
17 Python is an interpreted, interactive, object-oriented programming lan‐
18 guage that combines remarkable power with very clear syntax. For an
19 introduction to programming in Python, see the Python Tutorial. The
20 Python Library Reference documents built-in and standard types, con‐
21 stants, functions and modules. Finally, the Python Reference Manual
22 describes the syntax and semantics of the core language in (perhaps
23 too) much detail. (These documents may be located via the INTERNET
24 RESOURCES below; they may be installed on your system as well.)
25
26 Python's basic power can be extended with your own modules written in C
27 or C++. On most systems such modules may be dynamically loaded.
28 Python is also adaptable as an extension language for existing applica‐
29 tions. See the internal documentation for hints.
30
31 Documentation for installed Python modules and packages can be viewed
32 by running the pydoc program.
33
35 -B Don't write .py[co] files on import. See also PYTHONDONTWRITE‐
36 BYTECODE.
37
38 -c command
39 Specify the command to execute (see next section). This termi‐
40 nates the option list (following options are passed as arguments
41 to the command).
42
43 -d Turn on parser debugging output (for wizards only, depending on
44 compilation options).
45
46 -E Ignore environment variables like PYTHONPATH and PYTHONHOME that
47 modify the behavior of the interpreter.
48
49 -h , -? , --help
50 Prints the usage for the interpreter executable and exits.
51
52 -i When a script is passed as first argument or the -c option is
53 used, enter interactive mode after executing the script or the
54 command. It does not read the $PYTHONSTARTUP file. This can be
55 useful to inspect global variables or a stack trace when a
56 script raises an exception.
57
58 -m module-name
59 Searches sys.path for the named module and runs the correspond‐
60 ing .py file as a script.
61
62 -O Turn on basic optimizations. This changes the filename exten‐
63 sion for compiled (bytecode) files from .pyc to .pyo. Given
64 twice, causes docstrings to be discarded.
65
66 -OO Discard docstrings in addition to the -O optimizations.
67
68 -R Turn on "hash randomization", so that the hash() values of str,
69 bytes and datetime objects are "salted" with an unpredictable
70 pseudo-random value. Although they remain constant within an
71 individual Python process, they are not predictable between
72 repeated invocations of Python.
73
74 This is intended to provide protection against a denial of ser‐
75 vice caused by carefully-chosen inputs that exploit the worst
76 case performance of a dict construction, O(n^2) complexity. See
77 http://www.ocert.org/advisories/ocert-2011-003.html for details.
78
79 -Q argument
80 Division control; see PEP 238. The argument must be one of
81 "old" (the default, int/int and long/long return an int or
82 long), "new" (new division semantics, i.e. int/int and long/long
83 returns a float), "warn" (old division semantics with a warning
84 for int/int and long/long), or "warnall" (old division semantics
85 with a warning for all use of the division operator). For a use
86 of "warnall", see the Tools/scripts/fixdiv.py script.
87
88 -s Don't add user site directory to sys.path.
89
90 -S Disable the import of the module site and the site-dependent
91 manipulations of sys.path that it entails.
92
93 -t Issue a warning when a source file mixes tabs and spaces for
94 indentation in a way that makes it depend on the worth of a tab
95 expressed in spaces. Issue an error when the option is given
96 twice.
97
98 -u Force stdin, stdout and stderr to be totally unbuffered. On
99 systems where it matters, also put stdin, stdout and stderr in
100 binary mode. Note that there is internal buffering in xread‐
101 lines(), readlines() and file-object iterators ("for line in
102 sys.stdin") which is not influenced by this option. To work
103 around this, you will want to use "sys.stdin.readline()" inside
104 a "while 1:" loop.
105
106 -v Print a message each time a module is initialized, showing the
107 place (filename or built-in module) from which it is loaded.
108 When given twice, print a message for each file that is checked
109 for when searching for a module. Also provides information on
110 module cleanup at exit.
111
112 -V , --version
113 Prints the Python version number of the executable and exits.
114
115 -W argument
116 Warning control. Python sometimes prints warning message to
117 sys.stderr. A typical warning message has the following form:
118 file:line: category: message. By default, each warning is
119 printed once for each source line where it occurs. This option
120 controls how often warnings are printed. Multiple -W options
121 may be given; when a warning matches more than one option, the
122 action for the last matching option is performed. Invalid -W
123 options are ignored (a warning message is printed about invalid
124 options when the first warning is issued). Warnings can also be
125 controlled from within a Python program using the warnings mod‐
126 ule.
127
128 The simplest form of argument is one of the following action
129 strings (or a unique abbreviation): ignore to ignore all warn‐
130 ings; default to explicitly request the default behavior (print‐
131 ing each warning once per source line); all to print a warning
132 each time it occurs (this may generate many messages if a warn‐
133 ing is triggered repeatedly for the same source line, such as
134 inside a loop); module to print each warning only the first time
135 it occurs in each module; once to print each warning only the
136 first time it occurs in the program; or error to raise an excep‐
137 tion instead of printing a warning message.
138
139 The full form of argument is action:message:category:mod‐
140 ule:line. Here, action is as explained above but only applies
141 to messages that match the remaining fields. Empty fields match
142 all values; trailing empty fields may be omitted. The message
143 field matches the start of the warning message printed; this
144 match is case-insensitive. The category field matches the warn‐
145 ing category. This must be a class name; the match test whether
146 the actual warning category of the message is a subclass of the
147 specified warning category. The full class name must be given.
148 The module field matches the (fully-qualified) module name; this
149 match is case-sensitive. The line field matches the line num‐
150 ber, where zero matches all line numbers and is thus equivalent
151 to an omitted line number.
152
153 -x Skip the first line of the source. This is intended for a DOS
154 specific hack only. Warning: the line numbers in error messages
155 will be off by one!
156
157 -3 Warn about Python 3.x incompatibilities that 2to3 cannot triv‐
158 ially fix.
159
161 The interpreter interface resembles that of the UNIX shell: when called
162 with standard input connected to a tty device, it prompts for commands
163 and executes them until an EOF is read; when called with a file name
164 argument or with a file as standard input, it reads and executes a
165 script from that file; when called with -c command, it executes the
166 Python statement(s) given as command. Here command may contain multi‐
167 ple statements separated by newlines. Leading whitespace is signifi‐
168 cant in Python statements! In non-interactive mode, the entire input
169 is parsed before it is executed.
170
171 If available, the script name and additional arguments thereafter are
172 passed to the script in the Python variable sys.argv, which is a list
173 of strings (you must first import sys to be able to access it). If no
174 script name is given, sys.argv[0] is an empty string; if -c is used,
175 sys.argv[0] contains the string '-c'. Note that options interpreted by
176 the Python interpreter itself are not placed in sys.argv.
177
178 In interactive mode, the primary prompt is `>>>'; the second prompt
179 (which appears when a command is not complete) is `...'. The prompts
180 can be changed by assignment to sys.ps1 or sys.ps2. The interpreter
181 quits when it reads an EOF at a prompt. When an unhandled exception
182 occurs, a stack trace is printed and control returns to the primary
183 prompt; in non-interactive mode, the interpreter exits after printing
184 the stack trace. The interrupt signal raises the KeyboardInterrupt
185 exception; other UNIX signals are not caught (except that SIGPIPE is
186 sometimes ignored, in favor of the IOError exception). Error messages
187 are written to stderr.
188
190 These are subject to difference depending on local installation conven‐
191 tions; ${prefix} and ${exec_prefix} are installation-dependent and
192 should be interpreted as for GNU software; they may be the same. The
193 default for both is /usr/local.
194
195 ${exec_prefix}/bin/python
196 Recommended location of the interpreter.
197
198 ${prefix}/lib/python<version>
199 ${exec_prefix}/lib/python<version>
200 Recommended locations of the directories containing the standard
201 modules.
202
203 ${prefix}/include/python<version>
204 ${exec_prefix}/include/python<version>
205 Recommended locations of the directories containing the include
206 files needed for developing Python extensions and embedding the
207 interpreter.
208
209 ~/.pythonrc.py
210 User-specific initialization file loaded by the user module; not
211 used by default or by most applications.
212
214 PYTHONHOME
215 Change the location of the standard Python libraries. By
216 default, the libraries are searched in ${prefix}/lib/python<ver‐
217 sion> and ${exec_prefix}/lib/python<version>, where ${prefix}
218 and ${exec_prefix} are installation-dependent directories, both
219 defaulting to /usr/local. When $PYTHONHOME is set to a single
220 directory, its value replaces both ${prefix} and ${exec_prefix}.
221 To specify different values for these, set $PYTHONHOME to ${pre‐
222 fix}:${exec_prefix}.
223
224 PYTHONPATH
225 Augments the default search path for module files. The format
226 is the same as the shell's $PATH: one or more directory path‐
227 names separated by colons. Non-existent directories are
228 silently ignored. The default search path is installation
229 dependent, but generally begins with ${prefix}/lib/python<ver‐
230 sion> (see PYTHONHOME above). The default search path is always
231 appended to $PYTHONPATH. If a script argument is given, the
232 directory containing the script is inserted in the path in front
233 of $PYTHONPATH. The search path can be manipulated from within
234 a Python program as the variable sys.path.
235
236 PYTHONSTARTUP
237 If this is the name of a readable file, the Python commands in
238 that file are executed before the first prompt is displayed in
239 interactive mode. The file is executed in the same name space
240 where interactive commands are executed so that objects defined
241 or imported in it can be used without qualification in the
242 interactive session. You can also change the prompts sys.ps1
243 and sys.ps2 in this file.
244
245 PYTHONY2K
246 Set this to a non-empty string to cause the time module to
247 require dates specified as strings to include 4-digit years,
248 otherwise 2-digit years are converted based on rules described
249 in the time module documentation.
250
251 PYTHONOPTIMIZE
252 If this is set to a non-empty string it is equivalent to speci‐
253 fying the -O option. If set to an integer, it is equivalent to
254 specifying -O multiple times.
255
256 PYTHONDEBUG
257 If this is set to a non-empty string it is equivalent to speci‐
258 fying the -d option. If set to an integer, it is equivalent to
259 specifying -d multiple times.
260
261 PYTHONDONTWRITEBYTECODE
262 If this is set to a non-empty string it is equivalent to speci‐
263 fying the -B option (don't try to write .py[co] files).
264
265 PYTHONINSPECT
266 If this is set to a non-empty string it is equivalent to speci‐
267 fying the -i option.
268
269 PYTHONIOENCODING
270 If this is set before running the interpreter, it overrides the
271 encoding used for stdin/stdout/stderr, in the syntax encoding‐
272 name:errorhandler The errorhandler part is optional and has the
273 same meaning as in str.encode. For stderr, the errorhandler
274 part is ignored; the handler will always be ´backslashreplace´.
275
276 PYTHONNOUSERSITE
277 If this is set to a non-empty string it is equivalent to speci‐
278 fying the -s option (Don't add the user site directory to
279 sys.path).
280
281 PYTHONUNBUFFERED
282 If this is set to a non-empty string it is equivalent to speci‐
283 fying the -u option.
284
285 PYTHONVERBOSE
286 If this is set to a non-empty string it is equivalent to speci‐
287 fying the -v option. If set to an integer, it is equivalent to
288 specifying -v multiple times.
289
290 PYTHONWARNINGS
291 If this is set to a comma-separated string it is equivalent to
292 specifying the -W option for each separate value.
293
294 PYTHONHASHSEED
295 If this variable is set to "random", the effect is the same as
296 specifying the -R option: a random value is used to seed the
297 hashes of str, bytes and datetime objects.
298
299 If PYTHONHASHSEED is set to an integer value, it is used as a
300 fixed seed for generating the hash() of the types covered by the
301 hash randomization. Its purpose is to allow repeatable hashing,
302 such as for selftests for the interpreter itself, or to allow a
303 cluster of python processes to share hash values.
304
305 The integer must be a decimal number in the range
306 [0,4294967295]. Specifying the value 0 will lead to the same
307 hash values as when hash randomization is disabled.
308
310 The Python Software Foundation: https://www.python.org/psf/
311
313 Main website: https://www.python.org/
314 Documentation: https://docs.python.org/2/
315 Developer resources: https://docs.python.org/devguide/
316 Downloads: https://www.python.org/downloads/
317 Module repository: https://pypi.python.org/
318 Newsgroups: comp.lang.python, comp.lang.python.announce
319
321 Python is distributed under an Open Source license. See the file
322 "LICENSE" in the Python source distribution for information on terms &
323 conditions for accessing and otherwise using Python and for a DIS‐
324 CLAIMER OF ALL WARRANTIES.
325
326
327
328 PYTHON(1)