| LEFT | RIGHT |
| 1 .. highlightlang:: none | 1 .. highlightlang:: none |
| 2 | |
| 3 .. ATTENTION: You probably should update Misc/python.man, too, if you modify | |
| 4 .. this file. | |
| 5 | 2 |
| 6 .. _using-on-general: | 3 .. _using-on-general: |
| 7 | 4 |
| 8 Command line and environment | 5 Command line and environment |
| 9 ============================ | 6 ============================ |
| 10 | 7 |
| 11 The CPython interpreter scans the command line and the environment for various | 8 The CPython interpreter scans the command line and the environment for various |
| 12 settings. | 9 settings. |
| 13 | 10 |
| 14 .. impl-detail:: | 11 .. impl-detail:: |
| 15 | 12 |
| 16 Other implementations' command line schemes may differ. See | 13 Other implementations' command line schemes may differ. See |
| 17 :ref:`implementations` for further resources. | 14 :ref:`implementations` for further resources. |
| 18 | 15 |
| 19 | 16 |
| 20 .. _using-on-cmdline: | 17 .. _using-on-cmdline: |
| 21 | 18 |
| 22 Command line | 19 Command line |
| 23 ------------ | 20 ------------ |
| 24 | 21 |
| 25 When invoking Python, you may specify any of these options:: | 22 When invoking Python, you may specify any of these options:: |
| 26 | 23 |
| 27 python [-BdEiOQsStuUvVWxX3?] [-c command | -m module-name | script | - ] [ar
gs] | 24 python [-bBdEhiORsSuvVWx?] [-c command | -m module-name | script | - ] [args
] |
| 28 | 25 |
| 29 The most common use case is, of course, a simple invocation of a script:: | 26 The most common use case is, of course, a simple invocation of a script:: |
| 30 | 27 |
| 31 python myscript.py | 28 python myscript.py |
| 32 | 29 |
| 33 | 30 |
| 34 .. _using-on-interface-options: | 31 .. _using-on-interface-options: |
| 35 | 32 |
| 36 Interface options | 33 Interface options |
| 37 ~~~~~~~~~~~~~~~~~ | 34 ~~~~~~~~~~~~~~~~~ |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 100 |
| 104 python -mtimeit -s 'setup here' 'benchmarked code here' | 101 python -mtimeit -s 'setup here' 'benchmarked code here' |
| 105 python -mtimeit -h # for details | 102 python -mtimeit -h # for details |
| 106 | 103 |
| 107 .. seealso:: | 104 .. seealso:: |
| 108 :func:`runpy.run_module` | 105 :func:`runpy.run_module` |
| 109 Equivalent functionality directly available to Python code | 106 Equivalent functionality directly available to Python code |
| 110 | 107 |
| 111 :pep:`338` -- Executing modules as scripts | 108 :pep:`338` -- Executing modules as scripts |
| 112 | 109 |
| 113 .. versionadded:: 2.4 | 110 |
| 114 | 111 .. versionchanged:: 3.1 |
| 115 .. versionchanged:: 2.5 | |
| 116 The named module can now be located inside a package. | |
| 117 | |
| 118 .. versionchanged:: 2.7 | |
| 119 Supply the package name to run a ``__main__`` submodule. | 112 Supply the package name to run a ``__main__`` submodule. |
| 120 sys.argv[0] is now set to ``"-m"`` while searching for the module | |
| 121 (it was previously incorrectly set to ``"-c"``) | |
| 122 | |
| 123 | 113 |
| 124 .. describe:: - | 114 .. describe:: - |
| 125 | 115 |
| 126 Read commands from standard input (:data:`sys.stdin`). If standard input is | 116 Read commands from standard input (:data:`sys.stdin`). If standard input is |
| 127 a terminal, :option:`-i` is implied. | 117 a terminal, :option:`-i` is implied. |
| 128 | 118 |
| 129 If this option is given, the first element of :data:`sys.argv` will be | 119 If this option is given, the first element of :data:`sys.argv` will be |
| 130 ``"-"`` and the current directory will be added to the start of | 120 ``"-"`` and the current directory will be added to the start of |
| 131 :data:`sys.path`. | 121 :data:`sys.path`. |
| 132 | 122 |
| 133 | 123 |
| 134 .. describe:: <script> | 124 .. describe:: <script> |
| 135 | 125 |
| 136 Execute the Python code contained in *script*, which must be a filesystem | 126 Execute the Python code contained in *script*, which must be a filesystem |
| 137 path (absolute or relative) referring to either a Python file, a directory | 127 path (absolute or relative) referring to either a Python file, a directory |
| 138 containing a ``__main__.py`` file, or a zipfile containing a | 128 containing a ``__main__.py`` file, or a zipfile containing a |
| 139 ``__main__.py`` file. | 129 ``__main__.py`` file. |
| 140 | 130 |
| 141 If this option is given, the first element of :data:`sys.argv` will be the | 131 If this option is given, the first element of :data:`sys.argv` will be the |
| 142 script name as given on the command line. | 132 script name as given on the command line. |
| 143 | 133 |
| 144 If the script name refers directly to a Python file, the directory | 134 If the script name refers directly to a Python file, the directory |
| 145 containing that file is added to the start of :data:`sys.path`, and the | 135 containing that file is added to the start of :data:`sys.path`, and the |
| 146 file is executed as the :mod:`__main__` module. | 136 file is executed as the :mod:`__main__` module. |
| 147 | 137 |
| 148 If the script name refers to a directory or zipfile, the script name is | 138 If the script name refers to a directory or zipfile, the script name is |
| 149 added to the start of :data:`sys.path` and the ``__main__.py`` file in | 139 added to the start of :data:`sys.path` and the ``__main__.py`` file in |
| 150 that location is executed as the :mod:`__main__` module. | 140 that location is executed as the :mod:`__main__` module. |
| 151 | 141 |
| 152 .. versionchanged:: 2.5 | |
| 153 Directories and zipfiles containing a ``__main__.py`` file at the top | |
| 154 level are now considered valid Python scripts. | |
| 155 | 142 |
| 156 If no interface option is given, :option:`-i` is implied, ``sys.argv[0]`` is | 143 If no interface option is given, :option:`-i` is implied, ``sys.argv[0]`` is |
| 157 an empty string (``""``) and the current directory will be added to the | 144 an empty string (``""``) and the current directory will be added to the |
| 158 start of :data:`sys.path`. | 145 start of :data:`sys.path`. |
| 159 | 146 |
| 160 .. seealso:: :ref:`tut-invoking` | 147 .. seealso:: :ref:`tut-invoking` |
| 161 | 148 |
| 162 | 149 |
| 163 Generic options | 150 Generic options |
| 164 ~~~~~~~~~~~~~~~ | 151 ~~~~~~~~~~~~~~~ |
| 165 | 152 |
| 166 .. cmdoption:: -? | 153 .. cmdoption:: -? |
| 167 -h | 154 -h |
| 168 --help | 155 --help |
| 169 | 156 |
| 170 Print a short description of all command line options. | 157 Print a short description of all command line options. |
| 171 | 158 |
| 172 .. versionchanged:: 2.5 | |
| 173 The ``--help`` variant. | |
| 174 | |
| 175 | 159 |
| 176 .. cmdoption:: -V | 160 .. cmdoption:: -V |
| 177 --version | 161 --version |
| 178 | 162 |
| 179 Print the Python version number and exit. Example output could be:: | 163 Print the Python version number and exit. Example output could be:: |
| 180 | 164 |
| 181 Python 2.5.1 | 165 Python 3.0 |
| 182 | |
| 183 .. versionchanged:: 2.5 | |
| 184 The ``--version`` variant. | |
| 185 | 166 |
| 186 | 167 |
| 187 Miscellaneous options | 168 Miscellaneous options |
| 188 ~~~~~~~~~~~~~~~~~~~~~ | 169 ~~~~~~~~~~~~~~~~~~~~~ |
| 189 | 170 |
| 171 .. cmdoption:: -b |
| 172 |
| 173 Issue a warning when comparing str and bytes. Issue an error when the |
| 174 option is given twice (:option:`-bb`). |
| 175 |
| 176 |
| 190 .. cmdoption:: -B | 177 .. cmdoption:: -B |
| 191 | 178 |
| 192 If given, Python won't try to write ``.pyc`` or ``.pyo`` files on the | 179 If given, Python won't try to write ``.pyc`` or ``.pyo`` files on the |
| 193 import of source modules. See also :envvar:`PYTHONDONTWRITEBYTECODE`. | 180 import of source modules. See also :envvar:`PYTHONDONTWRITEBYTECODE`. |
| 194 | 181 |
| 195 .. versionadded:: 2.6 | |
| 196 | |
| 197 | 182 |
| 198 .. cmdoption:: -d | 183 .. cmdoption:: -d |
| 199 | 184 |
| 200 Turn on parser debugging output (for wizards only, depending on compilation | 185 Turn on parser debugging output (for wizards only, depending on compilation |
| 201 options). See also :envvar:`PYTHONDEBUG`. | 186 options). See also :envvar:`PYTHONDEBUG`. |
| 202 | 187 |
| 203 | 188 |
| 204 .. cmdoption:: -E | 189 .. cmdoption:: -E |
| 205 | 190 |
| 206 Ignore all :envvar:`PYTHON*` environment variables, e.g. | 191 Ignore all :envvar:`PYTHON*` environment variables, e.g. |
| 207 :envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set. | 192 :envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set. |
| 208 | |
| 209 .. versionadded:: 2.2 | |
| 210 | 193 |
| 211 | 194 |
| 212 .. cmdoption:: -i | 195 .. cmdoption:: -i |
| 213 | 196 |
| 214 When a script is passed as first argument or the :option:`-c` option is used, | 197 When a script is passed as first argument or the :option:`-c` option is used, |
| 215 enter interactive mode after executing the script or the command, even when | 198 enter interactive mode after executing the script or the command, even when |
| 216 :data:`sys.stdin` does not appear to be a terminal. The | 199 :data:`sys.stdin` does not appear to be a terminal. The |
| 217 :envvar:`PYTHONSTARTUP` file is not read. | 200 :envvar:`PYTHONSTARTUP` file is not read. |
| 218 | 201 |
| 219 This can be useful to inspect global variables or a stack trace when a script | 202 This can be useful to inspect global variables or a stack trace when a script |
| 220 raises an exception. See also :envvar:`PYTHONINSPECT`. | 203 raises an exception. See also :envvar:`PYTHONINSPECT`. |
| 221 | 204 |
| 222 | 205 |
| 223 .. cmdoption:: -O | 206 .. cmdoption:: -O |
| 224 | 207 |
| 225 Turn on basic optimizations. This changes the filename extension for | 208 Turn on basic optimizations. This changes the filename extension for |
| 226 compiled (:term:`bytecode`) files from ``.pyc`` to ``.pyo``. See also | 209 compiled (:term:`bytecode`) files from ``.pyc`` to ``.pyo``. See also |
| 227 :envvar:`PYTHONOPTIMIZE`. | 210 :envvar:`PYTHONOPTIMIZE`. |
| 228 | 211 |
| 229 | 212 |
| 230 .. cmdoption:: -OO | 213 .. cmdoption:: -OO |
| 231 | 214 |
| 232 Discard docstrings in addition to the :option:`-O` optimizations. | 215 Discard docstrings in addition to the :option:`-O` optimizations. |
| 233 | 216 |
| 234 | 217 |
| 235 .. cmdoption:: -Q <arg> | 218 .. cmdoption:: -R |
| 236 | 219 |
| 237 Division control. The argument must be one of the following: | 220 Turn on hash randomization, so that the :meth:`__hash__` values of str, bytes |
| 238 | 221 and datetime objects are "salted" with an unpredictable random value. |
| 239 ``old`` | 222 Although they remain constant within an individual Python process, they are |
| 240 division of int/int and long/long return an int or long (*default*) | 223 not predictable between repeated invocations of Python. |
| 241 ``new`` | 224 |
| 242 new division semantics, i.e. division of int/int and long/long returns a | 225 This is intended to provide protection against a denial-of-service caused by |
| 243 float | 226 carefully-chosen inputs that exploit the worst case performance of a dict |
| 244 ``warn`` | 227 insertion, O(n^2) complexity. See |
| 245 old division semantics with a warning for int/int and long/long | 228 http://www.ocert.org/advisories/ocert-2011-003.html for details. |
| 246 ``warnall`` | 229 |
| 247 old division semantics with a warning for all uses of the division operator | 230 Changing hash values affects the order in which keys are retrieved from a |
| 248 | 231 dict. Although Python has never made guarantees about this ordering (and it |
| 249 .. seealso:: | 232 typically varies between 32-bit and 64-bit builds), enough real-world code |
| 250 :file:`Tools/scripts/fixdiv.py` | 233 implicitly relies on this non-guaranteed behavior that the randomization is |
| 251 for a use of ``warnall`` | 234 disabled by default. |
| 252 | 235 |
| 253 :pep:`238` -- Changing the division operator | 236 See also :envvar:`PYTHONHASHSEED`. |
| 237 |
| 238 .. versionadded:: 3.1.5 |
| 254 | 239 |
| 255 | 240 |
| 256 .. cmdoption:: -s | 241 .. cmdoption:: -s |
| 257 | 242 |
| 258 Don't add the :data:`user site-packages directory <site.USER_SITE>` to | 243 Don't add user site directory to sys.path |
| 259 :data:`sys.path`. | |
| 260 | |
| 261 .. versionadded:: 2.6 | |
| 262 | 244 |
| 263 .. seealso:: | 245 .. seealso:: |
| 264 | 246 |
| 265 :pep:`370` -- Per user site-packages directory | 247 :pep:`370` -- Per user site-packages directory |
| 266 | 248 |
| 267 | 249 |
| 268 .. cmdoption:: -S | 250 .. cmdoption:: -S |
| 269 | 251 |
| 270 Disable the import of the module :mod:`site` and the site-dependent | 252 Disable the import of the module :mod:`site` and the site-dependent |
| 271 manipulations of :data:`sys.path` that it entails. | 253 manipulations of :data:`sys.path` that it entails. |
| 272 | 254 |
| 273 | 255 |
| 274 .. cmdoption:: -t | |
| 275 | |
| 276 Issue a warning when a source file mixes tabs and spaces for indentation in a | |
| 277 way that makes it depend on the worth of a tab expressed in spaces. Issue an | |
| 278 error when the option is given twice (:option:`-tt`). | |
| 279 | |
| 280 | |
| 281 .. cmdoption:: -u | 256 .. cmdoption:: -u |
| 282 | 257 |
| 283 Force stdin, stdout and stderr to be totally unbuffered. On systems where it | 258 Force the binary layer of the stdin, stdout and stderr streams (which is |
| 284 matters, also put stdin, stdout and stderr in binary mode. | 259 available as their ``buffer`` attribute) to be unbuffered. The text I/O |
| 285 | 260 layer will still be line-buffered. |
| 286 Note that there is internal buffering in :meth:`file.readlines` and | |
| 287 :ref:`bltin-file-objects` (``for line in sys.stdin``) which is not influenced | |
| 288 by this option. To work around this, you will want to use | |
| 289 :meth:`file.readline` inside a ``while 1:`` loop. | |
| 290 | 261 |
| 291 See also :envvar:`PYTHONUNBUFFERED`. | 262 See also :envvar:`PYTHONUNBUFFERED`. |
| 292 | 263 |
| 293 | 264 |
| 294 .. cmdoption:: -v | 265 .. cmdoption:: -v |
| 295 | 266 |
| 296 Print a message each time a module is initialized, showing the place | 267 Print a message each time a module is initialized, showing the place |
| 297 (filename or built-in module) from which it is loaded. When given twice | 268 (filename or built-in module) from which it is loaded. When given twice |
| 298 (:option:`-vv`), print a message for each file that is checked for when | 269 (:option:`-vv`), print a message for each file that is checked for when |
| 299 searching for a module. Also provides information on module cleanup at exit. | 270 searching for a module. Also provides information on module cleanup at exit. |
| 300 See also :envvar:`PYTHONVERBOSE`. | 271 See also :envvar:`PYTHONVERBOSE`. |
| 301 | 272 |
| 302 | 273 |
| 303 .. cmdoption:: -W arg | 274 .. cmdoption:: -W arg |
| 304 | 275 |
| 305 Warning control. Python's warning machinery by default prints warning | 276 Warning control. Python's warning machinery by default prints warning |
| 306 messages to :data:`sys.stderr`. A typical warning message has the following | 277 messages to :data:`sys.stderr`. A typical warning message has the following |
| 307 form:: | 278 form:: |
| 308 | 279 |
| 309 file:line: category: message | 280 file:line: category: message |
| 310 | 281 |
| 311 By default, each warning is printed once for each source line where it | 282 By default, each warning is printed once for each source line where it |
| 312 occurs. This option controls how often warnings are printed. | 283 occurs. This option controls how often warnings are printed. |
| 313 | 284 |
| 314 Multiple :option:`-W` options may be given; when a warning matches more than | 285 Multiple :option:`-W` options may be given; when a warning matches more than |
| 315 one option, the action for the last matching option is performed. Invalid | 286 one option, the action for the last matching option is performed. Invalid |
| 316 :option:`-W` options are ignored (though, a warning message is printed about | 287 :option:`-W` options are ignored (though, a warning message is printed about |
| 317 invalid options when the first warning is issued). | 288 invalid options when the first warning is issued). |
| 318 | 289 |
| 319 Starting from Python 2.7, :exc:`DeprecationWarning` and its descendants | |
| 320 are ignored by default. The :option:`-Wd` option can be used to re-enable | |
| 321 them. | |
| 322 | |
| 323 Warnings can also be controlled from within a Python program using the | 290 Warnings can also be controlled from within a Python program using the |
| 324 :mod:`warnings` module. | 291 :mod:`warnings` module. |
| 325 | 292 |
| 326 The simplest form of argument is one of the following action strings (or a | 293 The simplest form of argument is one of the following action strings (or a |
| 327 unique abbreviation) by themselves: | 294 unique abbreviation): |
| 328 | 295 |
| 329 ``ignore`` | 296 ``ignore`` |
| 330 Ignore all warnings. | 297 Ignore all warnings. |
| 331 ``default`` | 298 ``default`` |
| 332 Explicitly request the default behavior (printing each warning once per | 299 Explicitly request the default behavior (printing each warning once per |
| 333 source line). | 300 source line). |
| 334 ``all`` | 301 ``all`` |
| 335 Print a warning each time it occurs (this may generate many messages if a | 302 Print a warning each time it occurs (this may generate many messages if a |
| 336 warning is triggered repeatedly for the same source line, such as inside a | 303 warning is triggered repeatedly for the same source line, such as inside a |
| 337 loop). | 304 loop). |
| 338 ``module`` | 305 ``module`` |
| 339 Print each warning only the first time it occurs in each module. | 306 Print each warning only the first time it occurs in each module. |
| 340 ``once`` | 307 ``once`` |
| 341 Print each warning only the first time it occurs in the program. | 308 Print each warning only the first time it occurs in the program. |
| 342 ``error`` | 309 ``error`` |
| 343 Raise an exception instead of printing a warning message. | 310 Raise an exception instead of printing a warning message. |
| 344 | 311 |
| 345 The full form of argument is:: | 312 The full form of argument is:: |
| 346 | 313 |
| 347 action:message:category:module:line | 314 action:message:category:module:line |
| 348 | 315 |
| 349 Here, *action* is as explained above but only applies to messages that match | 316 Here, *action* is as explained above but only applies to messages that match |
| 350 the remaining fields. Empty fields match all values; trailing empty fields | 317 the remaining fields. Empty fields match all values; trailing empty fields |
| 351 may be omitted. The *message* field matches the start of the warning message | 318 may be omitted. The *message* field matches the start of the warning message |
| 352 printed; this match is case-insensitive. The *category* field matches the | 319 printed; this match is case-insensitive. The *category* field matches the |
| 353 warning category. This must be a class name; the match tests whether the | 320 warning category. This must be a class name; the match test whether the |
| 354 actual warning category of the message is a subclass of the specified warning | 321 actual warning category of the message is a subclass of the specified warning |
| 355 category. The full class name must be given. The *module* field matches the | 322 category. The full class name must be given. The *module* field matches the |
| 356 (fully-qualified) module name; this match is case-sensitive. The *line* | 323 (fully-qualified) module name; this match is case-sensitive. The *line* |
| 357 field matches the line number, where zero matches all line numbers and is | 324 field matches the line number, where zero matches all line numbers and is |
| 358 thus equivalent to an omitted line number. | 325 thus equivalent to an omitted line number. |
| 359 | 326 |
| 360 .. seealso:: | 327 .. seealso:: |
| 361 :mod:`warnings` -- the warnings module | 328 :mod:`warnings` -- the warnings module |
| 362 | 329 |
| 363 :pep:`230` -- Warning framework | 330 :pep:`230` -- Warning framework |
| 364 | 331 |
| 365 :envvar:`PYTHONWARNINGS` | |
| 366 | |
| 367 | 332 |
| 368 .. cmdoption:: -x | 333 .. cmdoption:: -x |
| 369 | 334 |
| 370 Skip the first line of the source, allowing use of non-Unix forms of | 335 Skip the first line of the source, allowing use of non-Unix forms of |
| 371 ``#!cmd``. This is intended for a DOS specific hack only. | 336 ``#!cmd``. This is intended for a DOS specific hack only. |
| 372 | 337 |
| 373 .. note:: The line numbers in error messages will be off by one. | 338 .. note:: The line numbers in error messages will be off by one. |
| 374 | 339 |
| 375 .. cmdoption:: -3 | |
| 376 | |
| 377 Warn about Python 3.x incompatibilities which cannot be fixed trivially by | |
| 378 :ref:`2to3 <2to3-reference>`. Among these are: | |
| 379 | |
| 380 * :meth:`dict.has_key` | |
| 381 * :func:`apply` | |
| 382 * :func:`callable` | |
| 383 * :func:`coerce` | |
| 384 * :func:`execfile` | |
| 385 * :func:`reduce` | |
| 386 * :func:`reload` | |
| 387 | |
| 388 Using these will emit a :exc:`DeprecationWarning`. | |
| 389 | |
| 390 .. versionadded:: 2.6 | |
| 391 | 340 |
| 392 Options you shouldn't use | 341 Options you shouldn't use |
| 393 ~~~~~~~~~~~~~~~~~~~~~~~~~ | 342 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 394 | 343 |
| 395 .. cmdoption:: -J | 344 .. cmdoption:: -J |
| 396 | 345 |
| 397 Reserved for use by Jython_. | 346 Reserved for use by Jython_. |
| 398 | 347 |
| 399 .. _Jython: http://jython.org | 348 .. _Jython: http://jython.org |
| 400 | 349 |
| 401 .. cmdoption:: -U | |
| 402 | |
| 403 Turns all string literals into unicodes globally. Do not be tempted to use | |
| 404 this option as it will probably break your world. It also produces | |
| 405 ``.pyc`` files with a different magic number than normal. Instead, you can | |
| 406 enable unicode literals on a per-module basis by using:: | |
| 407 | |
| 408 from __future__ import unicode_literals | |
| 409 | |
| 410 at the top of the file. See :mod:`__future__` for details. | |
| 411 | |
| 412 .. cmdoption:: -X | 350 .. cmdoption:: -X |
| 413 | 351 |
| 414 Reserved for alternative implementations of Python to use for their own | 352 Reserved for alternative implementations of Python to use for their own |
| 415 purposes. | 353 purposes. |
| 354 |
| 416 | 355 |
| 417 .. _using-on-envvars: | 356 .. _using-on-envvars: |
| 418 | 357 |
| 419 Environment variables | 358 Environment variables |
| 420 --------------------- | 359 --------------------- |
| 421 | 360 |
| 422 These environment variables influence Python's behavior. | 361 These environment variables influence Python's behavior. |
| 423 | 362 |
| 424 .. envvar:: PYTHONHOME | 363 .. envvar:: PYTHONHOME |
| 425 | 364 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 | 452 |
| 514 If this is set, Python ignores case in :keyword:`import` statements. This | 453 If this is set, Python ignores case in :keyword:`import` statements. This |
| 515 only works on Windows. | 454 only works on Windows. |
| 516 | 455 |
| 517 | 456 |
| 518 .. envvar:: PYTHONDONTWRITEBYTECODE | 457 .. envvar:: PYTHONDONTWRITEBYTECODE |
| 519 | 458 |
| 520 If this is set, Python won't try to write ``.pyc`` or ``.pyo`` files on the | 459 If this is set, Python won't try to write ``.pyc`` or ``.pyo`` files on the |
| 521 import of source modules. | 460 import of source modules. |
| 522 | 461 |
| 523 .. versionadded:: 2.6 | |
| 524 | |
| 525 .. envvar:: PYTHONHASHRANDOMIZATION | |
| 526 | |
| 527 If this is set to a non-empty string, the hash() values of str, unicode | |
| 528 and buffer objects are randomized. Although they remain constant within | |
| 529 an individual Python process, they are not predictable between repeated | |
| 530 invocations of Python. | |
| 531 | |
| 532 This is intended to provide protection against a denial-of-service | |
| 533 caused by carefully-chosen inputs that exploit the worst case performance | |
| 534 of a dict lookup, O(n^2) complexity. See: | |
| 535 | |
| 536 http://www.ocert.org/advisories/ocert-2011-003.html | |
| 537 | |
| 538 for details. | |
| 539 | |
| 540 Changing hash values affects the order in which keys are retrieved from | |
| 541 a dict. Although Python has never made guarantees about this ordering | |
| 542 (and it typically varies between 32-bit and 64-bit builds), enough | |
| 543 real-world code implicitly relies on this non-guaranteed behavior that | |
| 544 the randomization is disabled by default. | |
| 545 | 462 |
| 546 .. envvar:: PYTHONHASHSEED | 463 .. envvar:: PYTHONHASHSEED |
| 547 | 464 |
| 548 If this is set, it is used as a fixed seed for generating the hash() of | 465 If this variable is set to ``random``, the effect is the same as specifying |
| 549 the types covererd by PYTHONHASHRANDOMIZATION. It should be a number in | 466 the :option:`-R` option: a random value is used to seed the hashes of str, |
| 550 the range [0; 4294967295]. The value 0 overrides the other variable and | 467 bytes and datetime objects. |
| 551 disables the hash randomization. | 468 |
| 469 If :envvar:`PYTHONHASHSEED` is set to an integer value, it is used as a fixed |
| 470 seed for generating the hash() of the types covered by the hash |
| 471 randomization. |
| 472 |
| 473 Its purpose is to allow repeatable hashing, such as for selftests for the |
| 474 interpreter itself, or to allow a cluster of python processes to share hash |
| 475 values. |
| 476 |
| 477 The integer must be a decimal number in the range [0,4294967295]. Specifying |
| 478 the value 0 will lead to the same hash values as when hash randomization is |
| 479 disabled. |
| 480 |
| 481 .. versionadded:: 3.1.5 |
| 482 |
| 552 | 483 |
| 553 .. envvar:: PYTHONIOENCODING | 484 .. envvar:: PYTHONIOENCODING |
| 554 | 485 |
| 555 Overrides the encoding used for stdin/stdout/stderr, in the syntax | 486 Overrides the encoding used for stdin/stdout/stderr, in the syntax |
| 556 ``encodingname:errorhandler``. The ``:errorhandler`` part is optional and | 487 ``encodingname:errorhandler``. The ``:errorhandler`` part is optional and |
| 557 has the same meaning as in :func:`str.encode`. | 488 has the same meaning as in :func:`str.encode`. |
| 558 | 489 |
| 559 .. versionadded:: 2.6 | 490 For stderr, the ``:errorhandler`` part is ignored; the handler will always be |
| 491 ``'backslashreplace'``. |
| 560 | 492 |
| 561 | 493 |
| 562 .. envvar:: PYTHONNOUSERSITE | 494 .. envvar:: PYTHONNOUSERSITE |
| 563 | 495 |
| 564 If this is set, Python won't add the :data:`user site-packages directory | 496 If this is set, Python won't add the user site directory to sys.path |
| 565 <site.USER_SITE>` to :data:`sys.path`. | |
| 566 | |
| 567 .. versionadded:: 2.6 | |
| 568 | 497 |
| 569 .. seealso:: | 498 .. seealso:: |
| 570 | 499 |
| 571 :pep:`370` -- Per user site-packages directory | 500 :pep:`370` -- Per user site-packages directory |
| 572 | 501 |
| 573 | 502 |
| 574 .. envvar:: PYTHONUSERBASE | 503 .. envvar:: PYTHONUSERBASE |
| 575 | 504 |
| 576 Defines the :data:`user base directory <site.USER_BASE>`, which is used to | 505 Sets the base directory for the user site directory |
| 577 compute the path of the :data:`user site-packages directory <site.USER_SITE>` | |
| 578 and :ref:`Distutils installation paths <inst-alt-install-user>` for ``python | |
| 579 setup.py install --user``. | |
| 580 | |
| 581 .. versionadded:: 2.6 | |
| 582 | 506 |
| 583 .. seealso:: | 507 .. seealso:: |
| 584 | 508 |
| 585 :pep:`370` -- Per user site-packages directory | 509 :pep:`370` -- Per user site-packages directory |
| 586 | 510 |
| 587 | 511 |
| 588 .. envvar:: PYTHONEXECUTABLE | 512 .. envvar:: PYTHONEXECUTABLE |
| 589 | 513 |
| 590 If this environment variable is set, ``sys.argv[0]`` will be set to its | 514 If this environment variable is set, ``sys.argv[0]`` will be set to its |
| 591 value instead of the value got through the C runtime. Only works on | 515 value instead of the value got through the C runtime. Only works on |
| 592 Mac OS X. | 516 Mac OS X. |
| 593 | 517 |
| 594 .. envvar:: PYTHONWARNINGS | |
| 595 | |
| 596 This is equivalent to the :option:`-W` option. If set to a comma | |
| 597 separated string, it is equivalent to specifying :option:`-W` multiple | |
| 598 times. | |
| 599 | |
| 600 | 518 |
| 601 Debug-mode variables | 519 Debug-mode variables |
| 602 ~~~~~~~~~~~~~~~~~~~~ | 520 ~~~~~~~~~~~~~~~~~~~~ |
| 603 | 521 |
| 604 Setting these variables only has an effect in a debug build of Python, that is, | 522 Setting these variables only has an effect in a debug build of Python, that is, |
| 605 if Python was configured with the ``--with-pydebug`` build option. | 523 if Python was configured with the :option:`--with-pydebug` build option. |
| 606 | 524 |
| 607 .. envvar:: PYTHONTHREADDEBUG | 525 .. envvar:: PYTHONTHREADDEBUG |
| 608 | 526 |
| 609 If set, Python will print threading debug info. | 527 If set, Python will print threading debug info. |
| 610 | 528 |
| 611 .. versionchanged:: 2.6 | |
| 612 Previously, this variable was called ``THREADDEBUG``. | |
| 613 | 529 |
| 614 .. envvar:: PYTHONDUMPREFS | 530 .. envvar:: PYTHONDUMPREFS |
| 615 | 531 |
| 616 If set, Python will dump objects and reference counts still alive after | 532 If set, Python will dump objects and reference counts still alive after |
| 617 shutting down the interpreter. | 533 shutting down the interpreter. |
| 618 | 534 |
| 619 | 535 |
| 620 .. envvar:: PYTHONMALLOCSTATS | 536 .. envvar:: PYTHONMALLOCSTATS |
| 621 | 537 |
| 622 If set, Python will print memory allocation statistics every time a new | 538 If set, Python will print memory allocation statistics every time a new |
| 623 object arena is created, and on shutdown. | 539 object arena is created, and on shutdown. |
| 624 | 540 |
| LEFT | RIGHT |