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.

473 lines
14 KiB

33 years ago
33 years ago
33 years ago
29 years ago
33 years ago
18 years ago
33 years ago
33 years ago
33 years ago
33 years ago
33 years ago
33 years ago
33 years ago
29 years ago
33 years ago
33 years ago
18 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
25 years ago
33 years ago
33 years ago
33 years ago
33 years ago
33 years ago
22 years ago
17 years ago
17 years ago
  1. .TH PYTHON "1" "$Date$"
  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 \-d
  13. ]
  14. [
  15. .B \-E
  16. ]
  17. [
  18. .B \-h
  19. ]
  20. [
  21. .B \-i
  22. ]
  23. [
  24. .B \-m
  25. .I module-name
  26. ]
  27. .br
  28. [
  29. .B \-O
  30. ]
  31. [
  32. .B \-OO
  33. ]
  34. [
  35. .B \-R
  36. ]
  37. [
  38. .B -Q
  39. .I argument
  40. ]
  41. [
  42. .B \-s
  43. ]
  44. [
  45. .B \-S
  46. ]
  47. [
  48. .B \-t
  49. ]
  50. [
  51. .B \-u
  52. ]
  53. .br
  54. [
  55. .B \-v
  56. ]
  57. [
  58. .B \-V
  59. ]
  60. [
  61. .B \-W
  62. .I argument
  63. ]
  64. [
  65. .B \-x
  66. ]
  67. [
  68. .B \-3
  69. ]
  70. [
  71. .B \-?
  72. ]
  73. .br
  74. [
  75. .B \-c
  76. .I command
  77. |
  78. .I script
  79. |
  80. \-
  81. ]
  82. [
  83. .I arguments
  84. ]
  85. .SH DESCRIPTION
  86. Python is an interpreted, interactive, object-oriented programming
  87. language that combines remarkable power with very clear syntax.
  88. For an introduction to programming in Python you are referred to the
  89. Python Tutorial.
  90. The Python Library Reference documents built-in and standard types,
  91. constants, functions and modules.
  92. Finally, the Python Reference Manual describes the syntax and
  93. semantics of the core language in (perhaps too) much detail.
  94. (These documents may be located via the
  95. .B "INTERNET RESOURCES"
  96. below; they may be installed on your system as well.)
  97. .PP
  98. Python's basic power can be extended with your own modules written in
  99. C or C++.
  100. On most systems such modules may be dynamically loaded.
  101. Python is also adaptable as an extension language for existing
  102. applications.
  103. See the internal documentation for hints.
  104. .PP
  105. Documentation for installed Python modules and packages can be
  106. viewed by running the
  107. .B pydoc
  108. program.
  109. .SH COMMAND LINE OPTIONS
  110. .TP
  111. .B \-B
  112. Don't write
  113. .I .py[co]
  114. files on import. See also PYTHONDONTWRITEBYTECODE.
  115. .TP
  116. .BI "\-c " command
  117. Specify the command to execute (see next section).
  118. This terminates the option list (following options are passed as
  119. arguments to the command).
  120. .TP
  121. .B \-d
  122. Turn on parser debugging output (for wizards only, depending on
  123. compilation options).
  124. .TP
  125. .B \-E
  126. Ignore environment variables like PYTHONPATH and PYTHONHOME that modify
  127. the behavior of the interpreter.
  128. .TP
  129. .B \-h ", " \-? ", "\-\-help
  130. Prints the usage for the interpreter executable and exits.
  131. .TP
  132. .B \-i
  133. When a script is passed as first argument or the \fB\-c\fP option is
  134. used, enter interactive mode after executing the script or the
  135. command. It does not read the $PYTHONSTARTUP file. This can be
  136. useful to inspect global variables or a stack trace when a script
  137. raises an exception.
  138. .TP
  139. .BI "\-m " module-name
  140. Searches
  141. .I sys.path
  142. for the named module and runs the corresponding
  143. .I .py
  144. file as a script.
  145. .TP
  146. .B \-O
  147. Turn on basic optimizations. This changes the filename extension for
  148. compiled (bytecode) files from
  149. .I .pyc
  150. to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
  151. .TP
  152. .B \-OO
  153. Discard docstrings in addition to the \fB-O\fP optimizations.
  154. .TP
  155. .B \-R
  156. Turn on "hash randomization", so that the hash() values of str, bytes and
  157. datetime objects are "salted" with an unpredictable pseudo-random value.
  158. Although they remain constant within an individual Python process, they are
  159. not predictable between repeated invocations of Python.
  160. .IP
  161. This is intended to provide protection against a denial of service
  162. caused by carefully-chosen inputs that exploit the worst case performance
  163. of a dict construction, O(n^2) complexity. See
  164. http://www.ocert.org/advisories/ocert-2011-003.html
  165. for details.
  166. .TP
  167. .BI "\-Q " argument
  168. Division control; see PEP 238. The argument must be one of "old" (the
  169. default, int/int and long/long return an int or long), "new" (new
  170. division semantics, i.e. int/int and long/long returns a float),
  171. "warn" (old division semantics with a warning for int/int and
  172. long/long), or "warnall" (old division semantics with a warning for
  173. all use of the division operator). For a use of "warnall", see the
  174. Tools/scripts/fixdiv.py script.
  175. .TP
  176. .B \-s
  177. Don't add user site directory to sys.path.
  178. .TP
  179. .B \-S
  180. Disable the import of the module
  181. .I site
  182. and the site-dependent manipulations of
  183. .I sys.path
  184. that it entails.
  185. .TP
  186. .B \-t
  187. Issue a warning when a source file mixes tabs and spaces for
  188. indentation in a way that makes it depend on the worth of a tab
  189. expressed in spaces. Issue an error when the option is given twice.
  190. .TP
  191. .B \-u
  192. Force stdin, stdout and stderr to be totally unbuffered. On systems
  193. where it matters, also put stdin, stdout and stderr in binary mode.
  194. Note that there is internal buffering in xreadlines(), readlines() and
  195. file-object iterators ("for line in sys.stdin") which is not
  196. influenced by this option. To work around this, you will want to use
  197. "sys.stdin.readline()" inside a "while 1:" loop.
  198. .TP
  199. .B \-v
  200. Print a message each time a module is initialized, showing the place
  201. (filename or built-in module) from which it is loaded. When given
  202. twice, print a message for each file that is checked for when
  203. searching for a module. Also provides information on module cleanup
  204. at exit.
  205. .TP
  206. .B \-V ", " \-\-version
  207. Prints the Python version number of the executable and exits.
  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. .B \-x
  273. Skip the first line of the source. This is intended for a DOS
  274. specific hack only. Warning: the line numbers in error messages will
  275. be off by one!
  276. .TP
  277. .B \-3
  278. Warn about Python 3.x incompatibilities that 2to3 cannot trivially fix.
  279. .SH INTERPRETER INTERFACE
  280. The interpreter interface resembles that of the UNIX shell: when
  281. called with standard input connected to a tty device, it prompts for
  282. commands and executes them until an EOF is read; when called with a
  283. file name argument or with a file as standard input, it reads and
  284. executes a
  285. .I script
  286. from that file;
  287. when called with
  288. .B \-c
  289. .I command,
  290. it executes the Python statement(s) given as
  291. .I command.
  292. Here
  293. .I command
  294. may contain multiple statements separated by newlines.
  295. Leading whitespace is significant in Python statements!
  296. In non-interactive mode, the entire input is parsed before it is
  297. executed.
  298. .PP
  299. If available, the script name and additional arguments thereafter are
  300. passed to the script in the Python variable
  301. .I sys.argv ,
  302. which is a list of strings (you must first
  303. .I import sys
  304. to be able to access it).
  305. If no script name is given,
  306. .I sys.argv[0]
  307. is an empty string; if
  308. .B \-c
  309. is used,
  310. .I sys.argv[0]
  311. contains the string
  312. .I '-c'.
  313. Note that options interpreted by the Python interpreter itself
  314. are not placed in
  315. .I sys.argv.
  316. .PP
  317. In interactive mode, the primary prompt is `>>>'; the second prompt
  318. (which appears when a command is not complete) is `...'.
  319. The prompts can be changed by assignment to
  320. .I sys.ps1
  321. or
  322. .I sys.ps2.
  323. The interpreter quits when it reads an EOF at a prompt.
  324. When an unhandled exception occurs, a stack trace is printed and
  325. control returns to the primary prompt; in non-interactive mode, the
  326. interpreter exits after printing the stack trace.
  327. The interrupt signal raises the
  328. .I Keyboard\%Interrupt
  329. exception; other UNIX signals are not caught (except that SIGPIPE is
  330. sometimes ignored, in favor of the
  331. .I IOError
  332. exception). Error messages are written to stderr.
  333. .SH FILES AND DIRECTORIES
  334. These are subject to difference depending on local installation
  335. conventions; ${prefix} and ${exec_prefix} are installation-dependent
  336. and should be interpreted as for GNU software; they may be the same.
  337. The default for both is \fI/usr/local\fP.
  338. .IP \fI${exec_prefix}/bin/python\fP
  339. Recommended location of the interpreter.
  340. .PP
  341. .I ${prefix}/lib/python<version>
  342. .br
  343. .I ${exec_prefix}/lib/python<version>
  344. .RS
  345. Recommended locations of the directories containing the standard
  346. modules.
  347. .RE
  348. .PP
  349. .I ${prefix}/include/python<version>
  350. .br
  351. .I ${exec_prefix}/include/python<version>
  352. .RS
  353. Recommended locations of the directories containing the include files
  354. needed for developing Python extensions and embedding the
  355. interpreter.
  356. .RE
  357. .IP \fI~/.pythonrc.py\fP
  358. User-specific initialization file loaded by the \fIuser\fP module;
  359. not used by default or by most applications.
  360. .SH ENVIRONMENT VARIABLES
  361. .IP PYTHONHOME
  362. Change the location of the standard Python libraries. By default, the
  363. libraries are searched in ${prefix}/lib/python<version> and
  364. ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix}
  365. are installation-dependent directories, both defaulting to
  366. \fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value
  367. replaces both ${prefix} and ${exec_prefix}. To specify different values
  368. for these, set $PYTHONHOME to ${prefix}:${exec_prefix}.
  369. .IP PYTHONPATH
  370. Augments the default search path for module files.
  371. The format is the same as the shell's $PATH: one or more directory
  372. pathnames separated by colons.
  373. Non-existent directories are silently ignored.
  374. The default search path is installation dependent, but generally
  375. begins with ${prefix}/lib/python<version> (see PYTHONHOME above).
  376. The default search path is always appended to $PYTHONPATH.
  377. If a script argument is given, the directory containing the script is
  378. inserted in the path in front of $PYTHONPATH.
  379. The search path can be manipulated from within a Python program as the
  380. variable
  381. .I sys.path .
  382. .IP PYTHONSTARTUP
  383. If this is the name of a readable file, the Python commands in that
  384. file are executed before the first prompt is displayed in interactive
  385. mode.
  386. The file is executed in the same name space where interactive commands
  387. are executed so that objects defined or imported in it can be used
  388. without qualification in the interactive session.
  389. You can also change the prompts
  390. .I sys.ps1
  391. and
  392. .I sys.ps2
  393. in this file.
  394. .IP PYTHONY2K
  395. Set this to a non-empty string to cause the \fItime\fP module to
  396. require dates specified as strings to include 4-digit years, otherwise
  397. 2-digit years are converted based on rules described in the \fItime\fP
  398. module documentation.
  399. .IP PYTHONOPTIMIZE
  400. If this is set to a non-empty string it is equivalent to specifying
  401. the \fB\-O\fP option. If set to an integer, it is equivalent to
  402. specifying \fB\-O\fP multiple times.
  403. .IP PYTHONDEBUG
  404. If this is set to a non-empty string it is equivalent to specifying
  405. the \fB\-d\fP option. If set to an integer, it is equivalent to
  406. specifying \fB\-d\fP multiple times.
  407. .IP PYTHONDONTWRITEBYTECODE
  408. If this is set to a non-empty string it is equivalent to specifying
  409. the \fB\-B\fP option (don't try to write
  410. .I .py[co]
  411. files).
  412. .IP PYTHONINSPECT
  413. If this is set to a non-empty string it is equivalent to specifying
  414. the \fB\-i\fP option.
  415. .IP PYTHONIOENCODING
  416. If this is set before running the interpreter, it overrides the encoding used
  417. for stdin/stdout/stderr, in the syntax
  418. .IB encodingname ":" errorhandler
  419. The
  420. .IB errorhandler
  421. part is optional and has the same meaning as in str.encode. For stderr, the
  422. .IB errorhandler
  423. part is ignored; the handler will always be \'backslashreplace\'.
  424. .IP PYTHONNOUSERSITE
  425. If this is set to a non-empty string it is equivalent to specifying the
  426. \fB\-s\fP option (Don't add the user site directory to sys.path).
  427. .IP PYTHONUNBUFFERED
  428. If this is set to a non-empty string it is equivalent to specifying
  429. the \fB\-u\fP option.
  430. .IP PYTHONVERBOSE
  431. If this is set to a non-empty string it is equivalent to specifying
  432. the \fB\-v\fP option. If set to an integer, it is equivalent to
  433. specifying \fB\-v\fP multiple times.
  434. .IP PYTHONWARNINGS
  435. If this is set to a comma-separated string it is equivalent to
  436. specifying the \fB\-W\fP option for each separate value.
  437. .IP PYTHONHASHSEED
  438. If this variable is set to "random", the effect is the same as specifying
  439. the \fB-R\fP option: a random value is used to seed the hashes of str,
  440. bytes and datetime objects.
  441. If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for
  442. generating the hash() of the types covered by the hash randomization. Its
  443. purpose is to allow repeatable hashing, such as for selftests for the
  444. interpreter itself, or to allow a cluster of python processes to share hash
  445. values.
  446. The integer must be a decimal number in the range [0,4294967295]. Specifying
  447. the value 0 will lead to the same hash values as when hash randomization is
  448. disabled.
  449. .SH AUTHOR
  450. The Python Software Foundation: http://www.python.org/psf
  451. .SH INTERNET RESOURCES
  452. Main website: http://www.python.org/
  453. .br
  454. Documentation: http://docs.python.org/
  455. .br
  456. Developer resources: http://docs.python.org/devguide/
  457. .br
  458. Downloads: http://python.org/download/
  459. .br
  460. Module repository: http://pypi.python.org/
  461. .br
  462. Newsgroups: comp.lang.python, comp.lang.python.announce
  463. .SH LICENSING
  464. Python is distributed under an Open Source license. See the file
  465. "LICENSE" in the Python source distribution for information on terms &
  466. conditions for accessing and otherwise using Python and for a
  467. DISCLAIMER OF ALL WARRANTIES.