Skip to content

Commit 1384ab5

Browse files
committed
提交“Python 源代码的组织”
1 parent 0852aee commit 1384ab5

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 第 1 部分:序章
44

55
- [前言](README.md)
6+
- [Python 源代码的组织](preface/codeOrganization.md)
67

78
## 第 2 部分:Python 内建对象
89

preface/codeOrganization.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Python 源代码的组织
2+
3+
## 源代码下载
4+
5+
Python 源代码可以在 GitHub 上方便的获取,执行:
6+
7+
```console
8+
git clone https://github.com/python/cpython.git
9+
git checkout v3.7.0
10+
```
11+
12+
即可获取 `Python 3.7.0` 版本的代码。
13+
14+
## 目录结构
15+
16+
进入源码目录,我们可以看到该目录下主要  包含以下文件(夹):
17+
18+
```console
19+
.
20+
├── Doc
21+
├── Grammar
22+
├── Include
23+
├── LICENSE
24+
├── Lib
25+
├── Mac
26+
├── Makefile.pre.in
27+
├── Misc
28+
├── Modules
29+
├── Objects
30+
├── PC
31+
├── PCbuild
32+
├── Parser
33+
├── Programs
34+
├── Python
35+
├── README.rst
36+
├── Tools
37+
├── aclocal.m4
38+
├── config.guess
39+
├── config.sub
40+
├── configure
41+
├── configure.ac
42+
├── install-sh
43+
├── m4
44+
├── pyconfig.h.in
45+
└── setup.py
46+
```
47+
48+
其中:
49+
50+
Include 目录:包含了 Python 提供的所有头文件,如果用户需要自己用 C 或 C++来编写自定义模块扩展 Python,那么就需要用到这里提供的头文件。
51+
52+
Lib 目录:包含了 Python 自带的所有标准库,且都是用 Python 语言编写的。
53+
54+
Modules 目录:包含了所有用 C 语言编写的模块,比如 math、hashlib 等。它们都是那些对速度要求非常严格的模块。而相比而言,Lib 目录下则是存放一些对速度没有太严格要求的模块,比如 os。
55+
56+
Parser 目录:包含了 Python 解释器中的 Scanner 和 Parser 部分,即对 Python 源代码进行词法分析和语法分析的部分。除此以外,此目录还包含了一些有用的工具,这些工具能够根据 Python 语言的语法自动生成 Python 语言的词法和语法分析器,与 YACC 非常类似。
57+
58+
Objects 目录:包含了所有 Python 的内建对象,包括整数、list、dict 等。同时,该目录还包括了 Python 在运行时需要的所有的内部使用对象的实现。
59+
60+
Python 目录:包含了 Python 解释器中的 Compiler 和执行引擎部分,是 Python 运行的核心所在。
61+
62+
PCBuild 目录:包含了 Visual Studio 2003 的工程文件,研究 Python 源代码就从这里开始(本书将采用 Visual Studio 2017 对 Python 进行编译)。
63+
64+
Programs 目录:包含了 Python 二进制可执行文件的源码。

0 commit comments

Comments
 (0)