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.

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