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.

566 lines
18 KiB

32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
11 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 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.
  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. .TP
  301. .B \-x
  302. Skip the first line of the source. This is intended for a DOS
  303. specific hack only. Warning: the line numbers in error messages will
  304. be off by one!
  305. .SH INTERPRETER INTERFACE
  306. The interpreter interface resembles that of the UNIX shell: when
  307. called with standard input connected to a tty device, it prompts for
  308. commands and executes them until an EOF is read; when called with a
  309. file name argument or with a file as standard input, it reads and
  310. executes a
  311. .I script
  312. from that file;
  313. when called with
  314. .B \-c
  315. .IR command ,
  316. it executes the Python statement(s) given as
  317. .IR command .
  318. Here
  319. .I command
  320. may contain multiple statements separated by newlines.
  321. Leading whitespace is significant in Python statements!
  322. In non-interactive mode, the entire input is parsed before it is
  323. executed.
  324. .PP
  325. If available, the script name and additional arguments thereafter are
  326. passed to the script in the Python variable
  327. .IR sys.argv ,
  328. which is a list of strings (you must first
  329. .I import sys
  330. to be able to access it).
  331. If no script name is given,
  332. .I sys.argv[0]
  333. is an empty string; if
  334. .B \-c
  335. is used,
  336. .I sys.argv[0]
  337. contains the string
  338. .I '-c'.
  339. Note that options interpreted by the Python interpreter itself
  340. are not placed in
  341. .IR sys.argv .
  342. .PP
  343. In interactive mode, the primary prompt is `>>>'; the second prompt
  344. (which appears when a command is not complete) is `...'.
  345. The prompts can be changed by assignment to
  346. .I sys.ps1
  347. or
  348. .IR sys.ps2 .
  349. The interpreter quits when it reads an EOF at a prompt.
  350. When an unhandled exception occurs, a stack trace is printed and
  351. control returns to the primary prompt; in non-interactive mode, the
  352. interpreter exits after printing the stack trace.
  353. The interrupt signal raises the
  354. .I Keyboard\%Interrupt
  355. exception; other UNIX signals are not caught (except that SIGPIPE is
  356. sometimes ignored, in favor of the
  357. .I IOError
  358. exception). Error messages are written to stderr.
  359. .SH FILES AND DIRECTORIES
  360. These are subject to difference depending on local installation
  361. conventions; ${prefix} and ${exec_prefix} are installation-dependent
  362. and should be interpreted as for GNU software; they may be the same.
  363. The default for both is \fI/usr/local\fP.
  364. .IP \fI${exec_prefix}/bin/python\fP
  365. Recommended location of the interpreter.
  366. .PP
  367. .I ${prefix}/lib/python<version>
  368. .br
  369. .I ${exec_prefix}/lib/python<version>
  370. .RS
  371. Recommended locations of the directories containing the standard
  372. modules.
  373. .RE
  374. .PP
  375. .I ${prefix}/include/python<version>
  376. .br
  377. .I ${exec_prefix}/include/python<version>
  378. .RS
  379. Recommended locations of the directories containing the include files
  380. needed for developing Python extensions and embedding the
  381. interpreter.
  382. .RE
  383. .SH ENVIRONMENT VARIABLES
  384. .IP PYTHONHOME
  385. Change the location of the standard Python libraries. By default, the
  386. libraries are searched in ${prefix}/lib/python<version> and
  387. ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
  388. are installation-dependent directories, both defaulting to
  389. \fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
  390. replaces both ${prefix} and ${exec_prefix}. To specify different values
  391. for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
  392. .IP PYTHONPATH
  393. Augments the default search path for module files.
  394. The format is the same as the shell's $PATH: one or more directory
  395. pathnames separated by colons.
  396. Non-existent directories are silently ignored.
  397. The default search path is installation dependent, but generally
  398. begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
  399. The default search path is always appended to $PYTHONPATH.
  400. If a script argument is given, the directory containing the script is
  401. inserted in the path in front of $PYTHONPATH.
  402. The search path can be manipulated from within a Python program as the
  403. variable
  404. .IR sys.path .
  405. .IP PYTHONSTARTUP
  406. If this is the name of a readable file, the Python commands in that
  407. file are executed before the first prompt is displayed in interactive
  408. mode.
  409. The file is executed in the same name space where interactive commands
  410. are executed so that objects defined or imported in it can be used
  411. without qualification in the interactive session.
  412. You can also change the prompts
  413. .I sys.ps1
  414. and
  415. .I sys.ps2
  416. in this file.
  417. .IP PYTHONOPTIMIZE
  418. If this is set to a non-empty string it is equivalent to specifying
  419. the \fB\-O\fP option. If set to an integer, it is equivalent to
  420. specifying \fB\-O\fP multiple times.
  421. .IP PYTHONDEBUG
  422. If this is set to a non-empty string it is equivalent to specifying
  423. the \fB\-d\fP option. If set to an integer, it is equivalent to
  424. specifying \fB\-d\fP multiple times.
  425. .IP PYTHONDONTWRITEBYTECODE
  426. If this is set to a non-empty string it is equivalent to specifying
  427. the \fB\-B\fP option (don't try to write
  428. .I .pyc
  429. files).
  430. .IP PYTHONINSPECT
  431. If this is set to a non-empty string it is equivalent to specifying
  432. the \fB\-i\fP option.
  433. .IP PYTHONIOENCODING
  434. If this is set before running the interpreter, it overrides the encoding used
  435. for stdin/stdout/stderr, in the syntax
  436. .IB encodingname ":" errorhandler
  437. The
  438. .IB errorhandler
  439. part is optional and has the same meaning as in str.encode. For stderr, the
  440. .IB errorhandler
  441. part is ignored; the handler will always be \'backslashreplace\'.
  442. .IP PYTHONNOUSERSITE
  443. If this is set to a non-empty string it is equivalent to specifying the
  444. \fB\-s\fP option (Don't add the user site directory to sys.path).
  445. .IP PYTHONUNBUFFERED
  446. If this is set to a non-empty string it is equivalent to specifying
  447. the \fB\-u\fP option.
  448. .IP PYTHONVERBOSE
  449. If this is set to a non-empty string it is equivalent to specifying
  450. the \fB\-v\fP option. If set to an integer, it is equivalent to
  451. specifying \fB\-v\fP multiple times.
  452. .IP PYTHONWARNINGS
  453. If this is set to a comma-separated string it is equivalent to
  454. specifying the \fB\-W\fP option for each separate value.
  455. .IP PYTHONHASHSEED
  456. If this variable is set to "random", a random value is used to seed the hashes
  457. of str and bytes objects.
  458. If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
  459. generating the hash() of the types covered by the hash randomization. Its
  460. purpose is to allow repeatable hashing, such as for selftests for the
  461. interpreter itself, or to allow a cluster of python processes to share hash
  462. values.
  463. The integer must be a decimal number in the range [0,4294967295]. Specifying
  464. the value 0 will disable hash randomization.
  465. .IP PYTHONMALLOC
  466. Set the Python memory allocators and/or install debug hooks. The available
  467. memory allocators are
  468. .IR malloc
  469. and
  470. .IR pymalloc .
  471. The available debug hooks are
  472. .IR debug ,
  473. .IR malloc_debug ,
  474. and
  475. .IR pymalloc_debug .
  476. .IP
  477. When Python is compiled in debug mode, the default is
  478. .IR pymalloc_debug
  479. and the debug hooks are automatically used. Otherwise, the default is
  480. .IR pymalloc .
  481. .IP PYTHONMALLOCSTATS
  482. If set to a non-empty string, Python will print statistics of the pymalloc
  483. memory allocator every time a new pymalloc object arena is created, and on
  484. shutdown.
  485. .IP
  486. This variable is ignored if the
  487. .RB $ PYTHONMALLOC
  488. environment variable is used to force the
  489. .BR malloc (3)
  490. allocator of the C library, or if Python is configured without pymalloc support.
  491. .IP PYTHONASYNCIODEBUG
  492. If this environment variable is set to a non-empty string, enable the debug
  493. mode of the asyncio module.
  494. .IP PYTHONTRACEMALLOC
  495. If this environment variable is set to a non-empty string, start tracing
  496. Python memory allocations using the tracemalloc module.
  497. .IP
  498. The value of the variable is the maximum number of frames stored in a
  499. traceback of a trace. For example,
  500. .IB PYTHONTRACEMALLOC=1
  501. stores only the most recent frame.
  502. .IP PYTHONFAULTHANDLER
  503. If this environment variable is set to a non-empty string,
  504. .IR faulthandler.enable()
  505. is called at startup: install a handler for SIGSEGV, SIGFPE, SIGABRT, SIGBUS
  506. and SIGILL signals to dump the Python traceback.
  507. .IP
  508. This is equivalent to the \fB-X faulthandler\fP option.
  509. .IP PYTHONEXECUTABLE
  510. If this environment variable is set,
  511. .IB sys.argv[0]
  512. will be set to its value instead of the value got through the C runtime. Only
  513. works on Mac OS X.
  514. .IP PYTHONUSERBASE
  515. Defines the user base directory, which is used to compute the path of the user
  516. .IR site-packages
  517. directory and Distutils installation paths for
  518. .IR "python setup\.py install \-\-user" .
  519. .IP PYTHONPROFILEIMPORTTIME
  520. If this environment variable is set to a non-empty string, Python will
  521. show how long each import takes. This is exactly equivalent to setting
  522. \fB\-X importtime\fP on the command line.
  523. .IP PYTHONBREAKPOINT
  524. If this environment variable is set to 0, it disables the default debugger. It
  525. can be set to the callable of your debugger of choice.
  526. .SS Debug-mode variables
  527. Setting these variables only has an effect in a debug build of Python, that is,
  528. if Python was configured with the
  529. \fB\--with-pydebug\fP build option.
  530. .IP PYTHONTHREADDEBUG
  531. If this environment variable is set, Python will print threading debug info.
  532. .IP PYTHONDUMPREFS
  533. If this environment variable is set, Python will dump objects and reference
  534. counts still alive after shutting down the interpreter.
  535. .SH AUTHOR
  536. The Python Software Foundation: https://www.python.org/psf/
  537. .SH INTERNET RESOURCES
  538. Main website: https://www.python.org/
  539. .br
  540. Documentation: https://docs.python.org/
  541. .br
  542. Developer resources: https://devguide.python.org/
  543. .br
  544. Downloads: https://www.python.org/downloads/
  545. .br
  546. Module repository: https://pypi.org/
  547. .br
  548. Newsgroups: comp.lang.python, comp.lang.python.announce
  549. .SH LICENSING
  550. Python is distributed under an Open Source license. See the file
  551. "LICENSE" in the Python source distribution for information on terms &
  552. conditions for accessing and otherwise using Python and for a
  553. DISCLAIMER OF ALL WARRANTIES.