Skip to content

Commit 38dac72

Browse files
committed
修改部分格式错误
1 parent 2133f93 commit 38dac72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+25941
-368
lines changed

build/doctrees/appendix.doctree

28.3 KB
Binary file not shown.

build/doctrees/appetite.doctree

14.2 KB
Binary file not shown.

build/doctrees/classes.doctree

148 KB
Binary file not shown.

build/doctrees/controlflow.doctree

113 KB
Binary file not shown.

build/doctrees/datastructures.doctree

98.9 KB
Binary file not shown.

build/doctrees/environment.pickle

69.6 KB
Binary file not shown.

build/doctrees/errors.doctree

68.3 KB
Binary file not shown.

build/doctrees/floatingpoint.doctree

43.9 KB
Binary file not shown.

build/doctrees/index.doctree

13.4 KB
Binary file not shown.

build/doctrees/inputoutput.doctree

76.2 KB
Binary file not shown.

build/doctrees/interactive.doctree

29.9 KB
Binary file not shown.

build/doctrees/interpreter.doctree

56.5 KB
Binary file not shown.

build/doctrees/introduction.doctree

74.4 KB
Binary file not shown.

build/doctrees/modules.doctree

112 KB
Binary file not shown.

build/doctrees/stdlib.doctree

52.7 KB
Binary file not shown.

build/doctrees/stdlib2.doctree

58.2 KB
Binary file not shown.

build/doctrees/whatnow.doctree

16 KB
Binary file not shown.

build/html/.buildinfo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 46770cf01cde7d9665eaf2aed18a54a0
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

build/html/_sources/appendix.txt

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
.. _tut-appendix:
2+
3+
********
4+
Appendix
5+
********
6+
7+
8+
.. _tut-interac:
9+
10+
Interactive Mode
11+
================
12+
13+
.. _tut-error:
14+
15+
Error Handling
16+
--------------
17+
18+
When an error occurs, the interpreter prints an error message and a stack trace.
19+
In interactive mode, it then returns to the primary prompt; when input came from
20+
a file, it exits with a nonzero exit status after printing the stack trace.
21+
(Exceptions handled by an :keyword:`except` clause in a :keyword:`try` statement
22+
are not errors in this context.) Some errors are unconditionally fatal and
23+
cause an exit with a nonzero exit; this applies to internal inconsistencies and
24+
some cases of running out of memory. All error messages are written to the
25+
standard error stream; normal output from executed commands is written to
26+
standard output.
27+
28+
Typing the interrupt character (usually Control-C or DEL) to the primary or
29+
secondary prompt cancels the input and returns to the primary prompt. [#]_
30+
Typing an interrupt while a command is executing raises the
31+
:exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try`
32+
statement.
33+
34+
35+
.. _tut-scripts:
36+
37+
Executable Python Scripts
38+
-------------------------
39+
40+
On BSD'ish Unix systems, Python scripts can be made directly executable, like
41+
shell scripts, by putting the line ::
42+
43+
#!/usr/bin/env python3.4
44+
45+
(assuming that the interpreter is on the user's :envvar:`PATH`) at the beginning
46+
of the script and giving the file an executable mode. The ``#!`` must be the
47+
first two characters of the file. On some platforms, this first line must end
48+
with a Unix-style line ending (``'\n'``), not a Windows (``'\r\n'``) line
49+
ending. Note that the hash, or pound, character, ``'#'``, is used to start a
50+
comment in Python.
51+
52+
The script can be given an executable mode, or permission, using the
53+
:program:`chmod` command.
54+
55+
.. code-block:: bash
56+
57+
$ chmod +x myscript.py
58+
59+
On Windows systems, there is no notion of an "executable mode". The Python
60+
installer automatically associates ``.py`` files with ``python.exe`` so that
61+
a double-click on a Python file will run it as a script. The extension can
62+
also be ``.pyw``, in that case, the console window that normally appears is
63+
suppressed.
64+
65+
66+
.. _tut-startup:
67+
68+
The Interactive Startup File
69+
----------------------------
70+
71+
When you use Python interactively, it is frequently handy to have some standard
72+
commands executed every time the interpreter is started. You can do this by
73+
setting an environment variable named :envvar:`PYTHONSTARTUP` to the name of a
74+
file containing your start-up commands. This is similar to the :file:`.profile`
75+
feature of the Unix shells.
76+
77+
This file is only read in interactive sessions, not when Python reads commands
78+
from a script, and not when :file:`/dev/tty` is given as the explicit source of
79+
commands (which otherwise behaves like an interactive session). It is executed
80+
in the same namespace where interactive commands are executed, so that objects
81+
that it defines or imports can be used without qualification in the interactive
82+
session. You can also change the prompts ``sys.ps1`` and ``sys.ps2`` in this
83+
file.
84+
85+
If you want to read an additional start-up file from the current directory, you
86+
can program this in the global start-up file using code like ``if
87+
os.path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read())``.
88+
If you want to use the startup file in a script, you must do this explicitly
89+
in the script::
90+
91+
import os
92+
filename = os.environ.get('PYTHONSTARTUP')
93+
if filename and os.path.isfile(filename):
94+
with open(filename) as fobj:
95+
startup_file = fobj.read()
96+
exec(startup_file)
97+
98+
99+
.. _tut-customize:
100+
101+
The Customization Modules
102+
-------------------------
103+
104+
Python provides two hooks to let you customize it: :mod:`sitecustomize` and
105+
:mod:`usercustomize`. To see how it works, you need first to find the location
106+
of your user site-packages directory. Start Python and run this code::
107+
108+
>>> import site
109+
>>> site.getusersitepackages()
110+
'/home/user/.local/lib/python3.4/site-packages'
111+
112+
Now you can create a file named :file:`usercustomize.py` in that directory and
113+
put anything you want in it. It will affect every invocation of Python, unless
114+
it is started with the :option:`-s` option to disable the automatic import.
115+
116+
:mod:`sitecustomize` works in the same way, but is typically created by an
117+
administrator of the computer in the global site-packages directory, and is
118+
imported before :mod:`usercustomize`. See the documentation of the :mod:`site`
119+
module for more details.
120+
121+
122+
.. rubric:: Footnotes
123+
124+
.. [#] A problem with the GNU Readline package may prevent this.

build/html/_sources/appetite.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.. _tut-intro:
2+
3+
**********************
4+
开胃菜
5+
**********************
6+
7+
如果你要用计算机做很多工作,最后你会发现有一些任务你更希望用自动化的方式进行处理。比如,你想要在大量的文本文件中执行查找/替换,或者以复杂的方式对大量的图片进行重命名和整理。也许你想要编写一个小型的自定义数据库、一个特殊的 GUI 应用程序或一个简单的小游戏。
8+
9+
如果你是一名专业的软件开发者,可能你必须使用几种 C/C++/JAVA 类库,并且发现通常编写/编译/测试/重新编译的周期是如此漫长。也许你正在为这些类库编写测试用例,但是发现这是一个让人烦躁的工作。又或者你已经完成了一个可以使用扩展语言的程序,但你并不想为此重新设计并实现一套全新的语言。
10+
11+
那么 Python 正是你所需要的语言。
12+
13+
虽然你能够通过编写 Unix shell 脚本或 Windows 批处理文件来处理其中的某些任务,但 Shell 脚本更适合移动文件或修改文本数据,并不适合编写 GUI 应用程序或游戏;虽然你能够使用 C/C++/JAVA 编写程序,但即使编写一个简单的 first-draft 程序也有可能耗费大量的开发时间。相比之下,Python 更易于使用,无论在 Windows、Mac OS X 或 Unix 操作系统上它都会帮助你更快地完成任务。
14+
15+
虽然 Python 易于使用,但它却是一门完整的编程语言;与 Shell 脚本或批处理文件相比,它为编写大型程序提供了更多的结构和支持。另一方面,Python 提供了比 C 更多的错误检查,并且作为一门 *高级语言*,它内置支持高级的数据结构类型,例如:灵活的数组和字典。因其更多的通用数据类型,Python 比 Awk 甚至 Perl 都适用于更多问题领域,至少大多数事情在 Python 中与其他语言同样简单。
16+
17+
Python 允许你将程序分割为不同的模块,以便在其他的 Python 程序中重用。Python 内置提供了大量的标准模块,你可以将其用作程序的基础,或者作为学习 Python 编程的示例。这些模块提供了诸如文件 I/O、系统调用、Socket 支持,甚至类似 Tk 的用户图形界面(GUI)工具包接口。
18+
19+
Python 是一门解释型语言,因为无需编译和链接,你可以在程序开发中节省宝贵的时间。Python 解释器可以交互的使用,这使得试验语言的特性、编写临时程序或在自底向上的程序开发中测试方法非常容易。你甚至还可以把它当做一个桌面计算器。
20+
21+
Python 让程序编写的紧凑和可读。用 Python 编写的程序通常比同样的 C、C++ 或 Java 程序更短小,这是因为以下几个原因:
22+
23+
* 高级数据结构使你可以在一条语句中表达复杂的操作;
24+
25+
* 语句组使用缩进代替开始和结束大括号来组织;
26+
27+
* 变量或参数无需声明。
28+
29+
Python 是 *可扩展* 的:如果你会 C 语言编程便可以轻易地为解释器添加内置函数或模块,或者为了对性能瓶颈作优化,或者将 Python 程序与只有二进制形式的库(比如某个专业的商业图形库)连接起来。一旦你真正掌握了它,你可以将 Python 解释器集成进某个 C 应用程序,并把它当作那个程序的扩展或命令行语言。
30+
31+
顺便说一句,这个语言的名字来自于 BBC 的 “Monty Python’s Flying Cirecus” 节目,和爬行类动物没有任何关系。在文档中引用 Monty Python 的典故不仅可行,而且值得鼓励!
32+
33+
现在你已经为 Python 兴奋不已了吧,大概想要领略一些更多的细节!学习一门语言最好的方法就是使用它,本指南推荐你边读边使用 Python 解释器练习。
34+
35+
下一节中,我们将解释 Python 解释器的用法。这是很简单的一件事情,但它有助于试验后面的例子。
36+
37+
本手册剩下的部分将通过示例介绍 Python 语言及系统的诸多特性,开始是简单的语法、数据类型和表达式,接着介绍函数与模块,最后涉及异常和自定义类这样的高级内容。

0 commit comments

Comments
 (0)