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.

463 lines
14 KiB

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