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.

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