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 ] [ -O0 ] [ -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 you are referred to the Python
20 Tutorial. The Python Library Reference documents built-in and standard
21 types, constants, functions and modules. Finally, the Python Reference
22 Manual describes the syntax and semantics of the core language in (per‐
23 haps too) much detail. (These documents may be located via the INTER‐
24 NET 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 -O0 Discard docstrings in addition to the -O optimizations.
67
68 -R Turn on "hash randomization", so that the hash() values of str,
69 unicode, buffer and datetime objects are "salted" with an unpre‐
70 dictable pseudo-random value. Although they remain constant
71 within an individual Python process, they are not predictable
72 between 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 PYTHONNOUSERSITE
270 If this is set to a non-empty string it is equivalent to speci‐
271 fying the -s option (Don't add the user site directory to
272 sys.path).
273
274 PYTHONUNBUFFERED
275 If this is set to a non-empty string it is equivalent to speci‐
276 fying the -u option.
277
278 PYTHONVERBOSE
279 If this is set to a non-empty string it is equivalent to speci‐
280 fying the -v option. If set to an integer, it is equivalent to
281 specifying -v multiple times.
282
283 PYTHONHASHSEED
284 If this variable is set to "random", the effect is the same as
285 specifying the -R option: a random value is used to seed the
286 hashes of str, unicode, buffer and datetime objects.
287
288 If PYTHONHASHSEED is set to an integer value, it is used as a
289 fixed seed for generating the hash() of the types covered by the
290 hash randomization. Its purpose is to allow repeatable hashing,
291 such as for selftests for the interpreter itself, or to allow a
292 cluster of python processes to share hash values.
293
294 The integer must be a decimal number in the range
295 [0,4294967295]. Specifying the value 0 will lead to the same
296 hash values as when hash randomization is disabled.
297
299 The Python Software Foundation: http://www.python.org/psf
300
302 Main website: http://www.python.org/
303 Documentation: http://docs.python.org/
304 Developer resources: http://www.python.org/dev/
305 Downloads: http://python.org/download/
306 Module repository: http://pypi.python.org/
307 Newsgroups: comp.lang.python, comp.lang.python.announce
308
310 Python is distributed under an Open Source license. See the file
311 "LICENSE" in the Python source distribution for information on terms &
312 conditions for accessing and otherwise using Python and for a DIS‐
313 CLAIMER OF ALL WARRANTIES.
314
315
316
317 $Date: 2010-01-31 11:09:16 -0500 (Sun, 31 Jan 2010) $ PYTHON(1)