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.

450 lines
13 KiB

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