python3.9.1 18 KB

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