python3.7.1 13 KB

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