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.

452 lines
13 KiB

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