You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

569 lines
18 KiB

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