python3.11.1 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. .TH PYTHON "1"
  2. .\" To view this file while editing, run it through groff:
  3. .\" groff -Tascii -man python.man | less
  4. .SH NAME
  5. python \- an interpreted, interactive, object-oriented programming language
  6. .SH SYNOPSIS
  7. .B python
  8. [
  9. .B \-B
  10. ]
  11. [
  12. .B \-b
  13. ]
  14. [
  15. .B \-d
  16. ]
  17. [
  18. .B \-E
  19. ]
  20. [
  21. .B \-h
  22. ]
  23. [
  24. .B \-i
  25. ]
  26. [
  27. .B \-I
  28. ]
  29. .br
  30. [
  31. .B \-m
  32. .I module-name
  33. ]
  34. [
  35. .B \-q
  36. ]
  37. [
  38. .B \-O
  39. ]
  40. [
  41. .B \-OO
  42. ]
  43. [
  44. .B \-P
  45. ]
  46. [
  47. .B \-s
  48. ]
  49. [
  50. .B \-S
  51. ]
  52. [
  53. .B \-u
  54. ]
  55. .br
  56. [
  57. .B \-v
  58. ]
  59. [
  60. .B \-V
  61. ]
  62. [
  63. .B \-W
  64. .I argument
  65. ]
  66. [
  67. .B \-x
  68. ]
  69. [
  70. .B \-X
  71. .I option
  72. ]
  73. [
  74. .B \-?
  75. ]
  76. .br
  77. [
  78. .B \--check-hash-based-pycs
  79. .I default
  80. |
  81. .I always
  82. |
  83. .I never
  84. ]
  85. .br
  86. [
  87. .B \--help
  88. ]
  89. [
  90. .B \--help-env
  91. ]
  92. [
  93. .B \--help-xoptions
  94. ]
  95. [
  96. .B \--help-all
  97. ]
  98. .br
  99. [
  100. .B \-c
  101. .I command
  102. |
  103. .I script
  104. |
  105. \-
  106. ]
  107. [
  108. .I arguments
  109. ]
  110. .SH DESCRIPTION
  111. Python is an interpreted, interactive, object-oriented programming
  112. language that combines remarkable power with very clear syntax.
  113. For an introduction to programming in Python, see the Python Tutorial.
  114. The Python Library Reference documents built-in and standard types,
  115. constants, functions and modules.
  116. Finally, the Python Reference Manual describes the syntax and
  117. semantics of the core language in (perhaps too) much detail.
  118. (These documents may be located via the
  119. .B "INTERNET RESOURCES"
  120. below; they may be installed on your system as well.)
  121. .PP
  122. Python's basic power can be extended with your own modules written in
  123. C or C++.
  124. On most systems such modules may be dynamically loaded.
  125. Python is also adaptable as an extension language for existing
  126. applications.
  127. See the internal documentation for hints.
  128. .PP
  129. Documentation for installed Python modules and packages can be
  130. viewed by running the
  131. .B pydoc
  132. program.
  133. .SH COMMAND LINE OPTIONS
  134. .TP
  135. .B \-B
  136. Don't write
  137. .I .pyc
  138. files on import. See also PYTHONDONTWRITEBYTECODE.
  139. .TP
  140. .B \-b
  141. Issue warnings about str(bytes_instance), str(bytearray_instance)
  142. and comparing bytes/bytearray with str. (-bb: issue errors)
  143. .TP
  144. .BI "\-c " command
  145. Specify the command to execute (see next section).
  146. This terminates the option list (following options are passed as
  147. arguments to the command).
  148. .TP
  149. .BI "\-\-check-hash-based-pycs " mode
  150. Configure how Python evaluates the up-to-dateness of hash-based .pyc files.
  151. .TP
  152. .B \-d
  153. Turn on parser debugging output (for expert only, depending on
  154. compilation options).
  155. .TP
  156. .B \-E
  157. Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
  158. the behavior of the interpreter.
  159. .TP
  160. .B \-h ", " \-? ", "\-\-help
  161. Prints the usage for the interpreter executable and exits.
  162. .TP
  163. .B "\-\-help\-env"
  164. Prints help about Python-specific environment variables and exits.
  165. .TP
  166. .B "\-\-help\-xoptions"
  167. Prints help about implementation-specific \fB\-X\fP options and exits.
  168. .TP
  169. .TP
  170. .B "\-\-help\-all"
  171. Prints complete usage information and exits.
  172. .TP
  173. .B \-i
  174. When a script is passed as first argument or the \fB\-c\fP option is
  175. used, enter interactive mode after executing the script or the
  176. command. It does not read the $PYTHONSTARTUP file. This can be
  177. useful to inspect global variables or a stack trace when a script
  178. raises an exception.
  179. .TP
  180. .B \-I
  181. Run Python in isolated mode. This also implies \fB\-E\fP, \fB\-P\fP and \fB\-s\fP. In
  182. isolated mode sys.path contains neither the script's directory nor the user's
  183. site-packages directory. All PYTHON* environment variables are ignored, too.
  184. Further restrictions may be imposed to prevent the user from injecting
  185. malicious code.
  186. .TP
  187. .BI "\-m " module-name
  188. Searches
  189. .I sys.path
  190. for the named module and runs the corresponding
  191. .I .py
  192. file as a script. This terminates the option list (following options
  193. are passed as arguments to the module).
  194. .TP
  195. .B \-O
  196. Remove assert statements and any code conditional on the value of
  197. __debug__; augment the filename for compiled (bytecode) files by
  198. adding .opt-1 before the .pyc extension.
  199. .TP
  200. .B \-OO
  201. Do \fB-O\fP and also discard docstrings; change the filename for
  202. compiled (bytecode) files by adding .opt-2 before the .pyc extension.
  203. .TP
  204. .B \-P
  205. Don't automatically prepend a potentially unsafe path to \fBsys.path\fP such
  206. as the current directory, the script's directory or an empty string. See also the
  207. \fBPYTHONSAFEPATH\fP environment variable.
  208. .TP
  209. .B \-q
  210. Do not print the version and copyright messages. These messages are
  211. also suppressed in non-interactive mode.
  212. .TP
  213. .B \-s
  214. Don't add user site directory to sys.path.
  215. .TP
  216. .B \-S
  217. Disable the import of the module
  218. .I site
  219. and the site-dependent manipulations of
  220. .I sys.path
  221. that it entails. Also disable these manipulations if
  222. .I site
  223. is explicitly imported later.
  224. .TP
  225. .B \-u
  226. Force the stdout and stderr streams to be unbuffered.
  227. This option has no effect on the stdin stream.
  228. .TP
  229. .B \-v
  230. Print a message each time a module is initialized, showing the place
  231. (filename or built-in module) from which it is loaded. When given
  232. twice, print a message for each file that is checked for when
  233. searching for a module. Also provides information on module cleanup
  234. at exit.
  235. .TP
  236. .B \-V ", " \-\-version
  237. Prints the Python version number of the executable and exits. When given
  238. twice, print more information about the build.
  239. .TP
  240. .BI "\-W " argument
  241. Warning control. Python's warning machinery by default prints warning messages
  242. to
  243. .IR sys.stderr .
  244. The simplest settings apply a particular action unconditionally to all warnings
  245. emitted by a process (even those that are otherwise ignored by default):
  246. -Wdefault # Warn once per call location
  247. -Werror # Convert to exceptions
  248. -Walways # Warn every time
  249. -Wmodule # Warn once per calling module
  250. -Wonce # Warn once per Python process
  251. -Wignore # Never warn
  252. The action names can be abbreviated as desired and the interpreter will resolve
  253. them to the appropriate action name. For example,
  254. .B -Wi
  255. is the same as
  256. .B -Wignore .
  257. The full form of argument is:
  258. .IB action:message:category:module:lineno
  259. Empty fields match all values; trailing empty fields may be omitted. For
  260. example
  261. .B -W ignore::DeprecationWarning
  262. ignores all DeprecationWarning warnings.
  263. The
  264. .I action
  265. field is as explained above but only applies to warnings that match
  266. the remaining fields.
  267. The
  268. .I message
  269. field must match the whole printed warning message; this match is
  270. case-insensitive.
  271. The
  272. .I category
  273. field matches the warning category (ex: "DeprecationWarning"). This must be a
  274. class name; the match test whether the actual warning category of the message
  275. is a subclass of the specified warning category.
  276. The
  277. .I module
  278. field matches the (fully-qualified) module name; this match is case-sensitive.
  279. The
  280. .I lineno
  281. field matches the line number, where zero matches all line numbers and is thus
  282. equivalent to an omitted line number.
  283. Multiple
  284. .B -W
  285. options can be given; when a warning matches more than one option, the action
  286. for the last matching option is performed. Invalid
  287. .B -W
  288. options are ignored (though, a warning message is printed about invalid options
  289. when the first warning is issued).
  290. Warnings can also be controlled using the
  291. .B PYTHONWARNINGS
  292. environment variable and from within a Python program using the warnings
  293. module. For example, the warnings.filterwarnings() function can be used to use
  294. a regular expression on the warning message.
  295. .TP
  296. .BI "\-X " option
  297. Set implementation-specific option. The following options are available:
  298. -X faulthandler: enable faulthandler
  299. -X showrefcount: output the total reference count and number of used
  300. memory blocks when the program finishes or after each statement in the
  301. interactive interpreter. This only works on debug builds
  302. -X tracemalloc: start tracing Python memory allocations using the
  303. tracemalloc module. By default, only the most recent frame is stored in a
  304. traceback of a trace. Use -X tracemalloc=NFRAME to start tracing with a
  305. traceback limit of NFRAME frames
  306. -X importtime: show how long each import takes. It shows module name,
  307. cumulative time (including nested imports) and self time (excluding
  308. nested imports). Note that its output may be broken in multi-threaded
  309. application. Typical usage is python3 -X importtime -c 'import asyncio'
  310. -X dev: enable CPython's "development mode", introducing additional runtime
  311. checks which are too expensive to be enabled by default. It will not be
  312. more verbose than the default if the code is correct: new warnings are
  313. only emitted when an issue is detected. Effect of the developer mode:
  314. * Add default warning filter, as -W default
  315. * Install debug hooks on memory allocators: see the PyMem_SetupDebugHooks()
  316. C function
  317. * Enable the faulthandler module to dump the Python traceback on a crash
  318. * Enable asyncio debug mode
  319. * Set the dev_mode attribute of sys.flags to True
  320. * io.IOBase destructor logs close() exceptions
  321. -X utf8: enable UTF-8 mode for operating system interfaces, overriding the default
  322. locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode (even when it would
  323. otherwise activate automatically). See PYTHONUTF8 for more details
  324. -X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted at the
  325. given directory instead of to the code tree.
  326. -X warn_default_encoding: enable opt-in EncodingWarning for 'encoding=None'
  327. -X no_debug_ranges: disable the inclusion of the tables mapping extra location
  328. information (end line, start column offset and end column offset) to every
  329. instruction in code objects. This is useful when smaller code objects and pyc
  330. files are desired as well as suppressing the extra visual location indicators
  331. when the interpreter displays tracebacks.
  332. -X frozen_modules=[on|off]: whether or not frozen modules should be used.
  333. The default is "on" (or "off" if you are running a local build).
  334. -X int_max_str_digits=number: limit the size of int<->str conversions.
  335. This helps avoid denial of service attacks when parsing untrusted data.
  336. The default is sys.int_info.default_max_str_digits. 0 disables.
  337. .TP
  338. .B \-x
  339. Skip the first line of the source. This is intended for a DOS
  340. specific hack only. Warning: the line numbers in error messages will
  341. be off by one!
  342. .SH INTERPRETER INTERFACE
  343. The interpreter interface resembles that of the UNIX shell: when
  344. called with standard input connected to a tty device, it prompts for
  345. commands and executes them until an EOF is read; when called with a
  346. file name argument or with a file as standard input, it reads and
  347. executes a
  348. .I script
  349. from that file;
  350. when called with
  351. .B \-c
  352. .IR command ,
  353. it executes the Python statement(s) given as
  354. .IR command .
  355. Here
  356. .I command
  357. may contain multiple statements separated by newlines.
  358. Leading whitespace is significant in Python statements!
  359. In non-interactive mode, the entire input is parsed before it is
  360. executed.
  361. .PP
  362. If available, the script name and additional arguments thereafter are
  363. passed to the script in the Python variable
  364. .IR sys.argv ,
  365. which is a list of strings (you must first
  366. .I import sys
  367. to be able to access it).
  368. If no script name is given,
  369. .I sys.argv[0]
  370. is an empty string; if
  371. .B \-c
  372. is used,
  373. .I sys.argv[0]
  374. contains the string
  375. .I '-c'.
  376. Note that options interpreted by the Python interpreter itself
  377. are not placed in
  378. .IR sys.argv .
  379. .PP
  380. In interactive mode, the primary prompt is `>>>'; the second prompt
  381. (which appears when a command is not complete) is `...'.
  382. The prompts can be changed by assignment to
  383. .I sys.ps1
  384. or
  385. .IR sys.ps2 .
  386. The interpreter quits when it reads an EOF at a prompt.
  387. When an unhandled exception occurs, a stack trace is printed and
  388. control returns to the primary prompt; in non-interactive mode, the
  389. interpreter exits after printing the stack trace.
  390. The interrupt signal raises the
  391. .I Keyboard\%Interrupt
  392. exception; other UNIX signals are not caught (except that SIGPIPE is
  393. sometimes ignored, in favor of the
  394. .I IOError
  395. exception). Error messages are written to stderr.
  396. .SH FILES AND DIRECTORIES
  397. These are subject to difference depending on local installation
  398. conventions; ${prefix} and ${exec_prefix} are installation-dependent
  399. and should be interpreted as for GNU software; they may be the same.
  400. The default for both is \fI/usr/local\fP.
  401. .IP \fI${exec_prefix}/bin/python\fP
  402. Recommended location of the interpreter.
  403. .PP
  404. .I ${prefix}/lib/python<version>
  405. .br
  406. .I ${exec_prefix}/lib/python<version>
  407. .RS
  408. Recommended locations of the directories containing the standard
  409. modules.
  410. .RE
  411. .PP
  412. .I ${prefix}/include/python<version>
  413. .br
  414. .I ${exec_prefix}/include/python<version>
  415. .RS
  416. Recommended locations of the directories containing the include files
  417. needed for developing Python extensions and embedding the
  418. interpreter.
  419. .RE
  420. .SH ENVIRONMENT VARIABLES
  421. .IP PYTHONSAFEPATH
  422. If this is set to a non-empty string, don't automatically prepend a potentially
  423. unsafe path to \fBsys.path\fP such as the current directory, the script's
  424. directory or an empty string. See also the \fB\-P\fP option.
  425. .IP PYTHONHOME
  426. Change the location of the standard Python libraries. By default, the
  427. libraries are searched in ${prefix}/lib/python<version> and
  428. ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
  429. are installation-dependent directories, both defaulting to
  430. \fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
  431. replaces both ${prefix} and ${exec_prefix}. To specify different values
  432. for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
  433. .IP PYTHONPATH
  434. Augments the default search path for module files.
  435. The format is the same as the shell's $PATH: one or more directory
  436. pathnames separated by colons.
  437. Non-existent directories are silently ignored.
  438. The default search path is installation dependent, but generally
  439. begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
  440. The default search path is always appended to $PYTHONPATH.
  441. If a script argument is given, the directory containing the script is
  442. inserted in the path in front of $PYTHONPATH.
  443. The search path can be manipulated from within a Python program as the
  444. variable
  445. .IR sys.path .
  446. .IP PYTHONPLATLIBDIR
  447. Override sys.platlibdir.
  448. .IP PYTHONSTARTUP
  449. If this is the name of a readable file, the Python commands in that
  450. file are executed before the first prompt is displayed in interactive
  451. mode.
  452. The file is executed in the same name space where interactive commands
  453. are executed so that objects defined or imported in it can be used
  454. without qualification in the interactive session.
  455. You can also change the prompts
  456. .I sys.ps1
  457. and
  458. .I sys.ps2
  459. in this file.
  460. .IP PYTHONOPTIMIZE
  461. If this is set to a non-empty string it is equivalent to specifying
  462. the \fB\-O\fP option. If set to an integer, it is equivalent to
  463. specifying \fB\-O\fP multiple times.
  464. .IP PYTHONDEBUG
  465. If this is set to a non-empty string it is equivalent to specifying
  466. the \fB\-d\fP option. If set to an integer, it is equivalent to
  467. specifying \fB\-d\fP multiple times.
  468. .IP PYTHONDONTWRITEBYTECODE
  469. If this is set to a non-empty string it is equivalent to specifying
  470. the \fB\-B\fP option (don't try to write
  471. .I .pyc
  472. files).
  473. .IP PYTHONINSPECT
  474. If this is set to a non-empty string it is equivalent to specifying
  475. the \fB\-i\fP option.
  476. .IP PYTHONIOENCODING
  477. If this is set before running the interpreter, it overrides the encoding used
  478. for stdin/stdout/stderr, in the syntax
  479. .IB encodingname ":" errorhandler
  480. The
  481. .IB errorhandler
  482. part is optional and has the same meaning as in str.encode. For stderr, the
  483. .IB errorhandler
  484. part is ignored; the handler will always be \'backslashreplace\'.
  485. .IP PYTHONNOUSERSITE
  486. If this is set to a non-empty string it is equivalent to specifying the
  487. \fB\-s\fP option (Don't add the user site directory to sys.path).
  488. .IP PYTHONUNBUFFERED
  489. If this is set to a non-empty string it is equivalent to specifying
  490. the \fB\-u\fP option.
  491. .IP PYTHONVERBOSE
  492. If this is set to a non-empty string it is equivalent to specifying
  493. the \fB\-v\fP option. If set to an integer, it is equivalent to
  494. specifying \fB\-v\fP multiple times.
  495. .IP PYTHONWARNINGS
  496. If this is set to a comma-separated string it is equivalent to
  497. specifying the \fB\-W\fP option for each separate value.
  498. .IP PYTHONHASHSEED
  499. If this variable is set to "random", a random value is used to seed the hashes
  500. of str and bytes objects.
  501. If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
  502. generating the hash() of the types covered by the hash randomization. Its
  503. purpose is to allow repeatable hashing, such as for selftests for the
  504. interpreter itself, or to allow a cluster of python processes to share hash
  505. values.
  506. The integer must be a decimal number in the range [0,4294967295]. Specifying
  507. the value 0 will disable hash randomization.
  508. .IP PYTHONINTMAXSTRDIGITS
  509. Limit the maximum digit characters in an int value
  510. when converting from a string and when converting an int back to a str.
  511. A value of 0 disables the limit. Conversions to or from bases 2, 4, 8,
  512. 16, and 32 are never limited.
  513. .IP PYTHONMALLOC
  514. Set the Python memory allocators and/or install debug hooks. The available
  515. memory allocators are
  516. .IR malloc
  517. and
  518. .IR pymalloc .
  519. The available debug hooks are
  520. .IR debug ,
  521. .IR malloc_debug ,
  522. and
  523. .IR pymalloc_debug .
  524. .IP
  525. When Python is compiled in debug mode, the default is
  526. .IR pymalloc_debug
  527. and the debug hooks are automatically used. Otherwise, the default is
  528. .IR pymalloc .
  529. .IP PYTHONMALLOCSTATS
  530. If set to a non-empty string, Python will print statistics of the pymalloc
  531. memory allocator every time a new pymalloc object arena is created, and on
  532. shutdown.
  533. .IP
  534. This variable is ignored if the
  535. .RB $ PYTHONMALLOC
  536. environment variable is used to force the
  537. .BR malloc (3)
  538. allocator of the C library, or if Python is configured without pymalloc support.
  539. .IP PYTHONASYNCIODEBUG
  540. If this environment variable is set to a non-empty string, enable the debug
  541. mode of the asyncio module.
  542. .IP PYTHONTRACEMALLOC
  543. If this environment variable is set to a non-empty string, start tracing
  544. Python memory allocations using the tracemalloc module.
  545. .IP
  546. The value of the variable is the maximum number of frames stored in a
  547. traceback of a trace. For example,
  548. .IB PYTHONTRACEMALLOC=1
  549. stores only the most recent frame.
  550. .IP PYTHONFAULTHANDLER
  551. If this environment variable is set to a non-empty string,
  552. .IR faulthandler.enable()
  553. is called at startup: install a handler for SIGSEGV, SIGFPE, SIGABRT, SIGBUS
  554. and SIGILL signals to dump the Python traceback.
  555. .IP
  556. This is equivalent to the \fB-X faulthandler\fP option.
  557. .IP PYTHONEXECUTABLE
  558. If this environment variable is set,
  559. .IB sys.argv[0]
  560. will be set to its value instead of the value got through the C runtime. Only
  561. works on Mac OS X.
  562. .IP PYTHONUSERBASE
  563. Defines the user base directory, which is used to compute the path of the user
  564. .IR site-packages
  565. directory and Distutils installation paths for
  566. .IR "python setup\.py install \-\-user" .
  567. .IP PYTHONPROFILEIMPORTTIME
  568. If this environment variable is set to a non-empty string, Python will
  569. show how long each import takes. This is exactly equivalent to setting
  570. \fB\-X importtime\fP on the command line.
  571. .IP PYTHONBREAKPOINT
  572. If this environment variable is set to 0, it disables the default debugger. It
  573. can be set to the callable of your debugger of choice.
  574. .SS Debug-mode variables
  575. Setting these variables only has an effect in a debug build of Python, that is,
  576. if Python was configured with the
  577. \fB\--with-pydebug\fP build option.
  578. .IP PYTHONTHREADDEBUG
  579. If this environment variable is set, Python will print threading debug info.
  580. The feature is deprecated in Python 3.10 and will be removed in Python 3.12.
  581. .IP PYTHONDUMPREFS
  582. If this environment variable is set, Python will dump objects and reference
  583. counts still alive after shutting down the interpreter.
  584. .SH AUTHOR
  585. The Python Software Foundation: https://www.python.org/psf/
  586. .SH INTERNET RESOURCES
  587. Main website: https://www.python.org/
  588. .br
  589. Documentation: https://docs.python.org/
  590. .br
  591. Developer resources: https://devguide.python.org/
  592. .br
  593. Downloads: https://www.python.org/downloads/
  594. .br
  595. Module repository: https://pypi.org/
  596. .br
  597. Newsgroups: comp.lang.python, comp.lang.python.announce
  598. .SH LICENSING
  599. Python is distributed under an Open Source license. See the file
  600. "LICENSE" in the Python source distribution for information on terms &
  601. conditions for accessing and otherwise using Python and for a
  602. DISCLAIMER OF ALL WARRANTIES.