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.

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