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.

570 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 showalloccount: output the total count of allocated objects for each
  282. type when the program finishes. This only works when Python was built with
  283. COUNT_ALLOCS defined
  284. -X importtime: show how long each import takes. It shows module name,
  285. cumulative time (including nested imports) and self time (excluding
  286. nested imports). Note that its output may be broken in multi-threaded
  287. application. Typical usage is python3 -X importtime -c 'import asyncio'
  288. -X dev: enable CPython’s “development mode”, introducing additional runtime
  289. checks which are too expensive to be enabled by default. It will not be
  290. more verbose than the default if the code is correct: new warnings are
  291. only emitted when an issue is detected. Effect of the developer mode:
  292. * Add default warning filter, as -W default
  293. * Install debug hooks on memory allocators: see the PyMem_SetupDebugHooks() C function
  294. * Enable the faulthandler module to dump the Python traceback on a crash
  295. * Enable asyncio debug mode
  296. * Set the dev_mode attribute of sys.flags to True
  297. * io.IOBase destructor logs close() exceptions
  298. -X utf8: enable UTF-8 mode for operating system interfaces, overriding the default
  299. locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode (even when it would
  300. otherwise activate automatically). See PYTHONUTF8 for more details
  301. -X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted at the
  302. given directory instead of to the code tree.
  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 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.