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.

454 lines
13 KiB

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