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.

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