-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorepython-reading-notes-how-day7.html
More file actions
195 lines (149 loc) · 10.2 KB
/
corepython-reading-notes-how-day7.html
File metadata and controls
195 lines (149 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="index, follow" />
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,400;0,700;1,400&family=Source+Sans+Pro:ital,wght@0,300;0,400;0,700;1,400&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/stylesheet/style.min.css">
<link id="pygments-light-theme" rel="stylesheet" type="text/css"
href="https://blog.tonychow.me/theme/pygments/colorful.min.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/fontawesome.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/brands.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/solid.css">
<link href="https://blog.tonychow.me/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Tonychow's Blog Atom">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#333333">
<!-- Windows Phone -->
<meta name="msapplication-navbutton-color" content="#333333">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Microsoft EDGE -->
<meta name="msapplication-TileColor" content="#333333">
<meta name="author" content="tonychow" />
<meta name="description" content="" />
<meta name="keywords" content="corepython, reading-notes, python">
<meta property="og:site_name" content="Tonychow's Blog"/>
<meta property="og:title" content="Python 核心编程读书笔记 Day7"/>
<meta property="og:description" content=""/>
<meta property="og:locale" content="en_US"/>
<meta property="og:url" content="https://blog.tonychow.me/corepython-reading-notes-how-day7.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2014-07-18 00:00:00+08:00"/>
<meta property="article:modified_time" content=""/>
<meta property="article:author" content="https://blog.tonychow.me/author/tonychow.html">
<meta property="article:section" content="readings"/>
<meta property="article:tag" content="corepython"/>
<meta property="article:tag" content="reading-notes"/>
<meta property="article:tag" content="python"/>
<meta property="og:image" content="/images/avatar.jpg">
<title>Tonychow's Blog – Python 核心编程读书笔记 Day7</title>
</head>
<body class="light-theme">
<aside>
<div>
<a href="https://blog.tonychow.me/">
<img src="/images/avatar.jpg" alt="" title="">
</a>
<h1>
<a href="https://blog.tonychow.me/"></a>
</h1>
<p>Go/Python backend developer</p>
<ul class="social">
<li>
<a class="sc-github" href="https://github.com/chow1937" target="_blank">
<i class="fab fa-github"></i>
</a>
</li>
</ul>
</div>
</aside>
<main>
<nav>
<a href="https://blog.tonychow.me/">Home</a>
<a href="/archives.html">Archives</a>
<a href="/categories.html">Categories</a>
<a href="/tags.html">Tags</a>
<a href="https://blog.tonychow.me/feeds/all.atom.xml">Atom</a>
</nav>
<article class="single">
<header>
<h1 id="corepython-reading-notes-how-day7">Python 核心编程读书笔记 Day7</h1>
<p>
Posted on 五 18 七月 2014 in <a href="https://blog.tonychow.me/category/readings.html">readings</a>
• 1 min read
</p>
</header>
<div>
<p>今天把剩下的 20-23 章的内容阅读完毕了,这几章也是与 Python 相关的高级内容,包括 Web 编程,数据库接口和 Python 扩展等内容,下面稍微总结下每章的内容。</p>
<h3>第二十章:Web 编程</h3>
<p>这一章所谓的 Web 编程内容实际上讲的是利用 urllib 模块进行的 Web 相关的编程,同时也讲到了利用 cgi 模块进行的
原始的 cgi 编程。从内容来说的话主要介绍了 urllib 和 cgi 模块的一些使用。cgi 是比较早期的服务器处理客户端的
请求的方式,目前的 Python Web 编程已经不使用这种技术了。但是总的来说,过去和现在的 Web 编程总是接收请求,然后返回数据给客户端的模式。此外,鉴于 HTTP 协议的无状态性质,可以利用 cookie 的方式来在客户端和服务器端进行一定的状态判断。</p>
<h3>第二十一章:数据库编程</h3>
<p>无论是什么形式的应用程序,总会涉及到数据持久化的内容,而相比于普通的文件持久化或者 Python 提供的其他持久化的方式模块,利用数据库进行数据的持久化更适合复杂的数据和大型的系统。这章主要讲了 Python 利用数据库进行数据的持久化的内容,其中的数据库在本章主要指关系型数据库。Python 关于数据库这方面的内容,有一点让我觉得很牛逼的就是,它统一了一个数据库接口,也就是 PEP249 中规定的 Python 的 DB-API。这个规范规定了 Python 在数据库操作方面的一些通用的做法,任何依照这个规定实现的不同数据库的接口库都会表现出一致的操作方式。这样就大大地减少了程序员操作不同数据库的差异程度。虽然不是所有的接口都完全遵守,但是大体上是一致的。下面有几点:</p>
<p>1.<code>connect</code> 方法连接数据库;</p>
<p>2.<code>close</code> 方法关闭数据库连接;</p>
<p>3.<code>commit</code> 方法提交当前事务,对于不支持事务或者默认为立即执行的数据库来说,这个方法什么也不做;</p>
<p>4.<code>rollback</code> 方法取消当前事务,回滚到之前的状态;</p>
<p>5.<code>cursor</code> 获得一个游标对象,进行数据库的各种操作;</p>
<p>6.游标对象具有 <code>execute</code> 和 <code>executemany</code> 方法执行 SQL 查询或者操作;</p>
<p>7.游标对象具有 <code>fetchone</code>,<code>fetchmany</code> 和 <code>fetchall</code> 方法获取查询的结果;</p>
<p>8.ORM 框架是指对象关系映射框架,可以将一个对象映射为数据库中的数据内容,向使用者屏蔽了底层的数据库操作;</p>
<h3>第二十二章:扩展 Python</h3>
<p>这里讲到的扩展 Python 主要讲的是针对 CPython 的扩展。因为 CPython 的实现语言是 C ,所以我们也可以根据一定的方式,编写 C 语言程序,扩展 CPython 的功能。下面是要点:</p>
<p>1.扩展 CPython 的程序需要包含 Python.h 头文件;</p>
<p>2.扩展模块中的函数如果想要在 Python 中被调用,需要进行函数的包装,包装函数的模式为 PyObject * Module_func();</p>
<p>3.在 Python 中调用扩展模块的函数时,传入的是 Python 的数据类型,所以需要用 <code>PyArg_Parse*</code> 系列函数将参数转换为 C 的数据类型;</p>
<p>4.同样地,扩展模块的函数返回的是 C 的数据类型,也需要将这个返回结果通过 <code>Py_BuildValue</code> 进行类型的转换然后再返回;</p>
<p>5.扩展模块的 C 源码编写好后可以通过 distutils 模块对其进行编译和添加进 Python 的模块目录中;</p>
<p>6.注意在扩展模块中如果想利用 Python 的对象,需要考虑引用计数的问题;</p>
<p>7.由于扩展模块的代码最终也会在 Python 解释器中执行,所以同样也会受到 GIL 的影响;</p>
<h3>第二十三章:其他话题</h3>
<p>本章的内容是一些杂七杂八的内容,比如利用 Python 编写一个利用其他在线的 Web 服务的脚本程序,利用 COM 接口调用 win 平台的 office 软件还有发送邮件等内容。最后还提到了Jython 的内容,利用 Swing 进行 GUI 开发。</p>
<h3>最终总结</h3>
<p>花了大概一周的时间,看完了《Python 核心编程这本书》。这本书从内容来说,还是不错的,一些 Python 基本的东西都有涉及,也讲得很细,也有些经验之谈的东西也值得学习。虽然后面的章节有点凑字数的嫌疑,考虑是到面向的是 Python2.5,而现在 Python 的版本号已经跑到了 2.7 了,所以也能原谅。但是,中文版的质量真心的差强人意。不说遍布全书的各种 typo 问题(甚至连标题也出现 typo),就一点来说,对于 Python 这种这么注重缩进的语言来说,书里的各种代码缩进乱七八糟真的好意思么。当然,考虑到这本中文版出书背后的各种八卦事情,似乎这种质量也是可以理解的。</p>
<p>无论如何,看完这本书之后的确对 Python 有了更多的了解,或者说对 Python 的理解更加全面了,所以还是受益匪浅的。</p>
</div>
<div class="tag-cloud">
<p>
<a href="https://blog.tonychow.me/tag/corepython.html">corepython</a>
<a href="https://blog.tonychow.me/tag/reading-notes.html">reading-notes</a>
<a href="https://blog.tonychow.me/tag/python.html">python</a>
</p>
</div>
</article>
<footer>
<p>
© 2017 - This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/deed.en_US" target="_blank">Creative Commons Attribution-ShareAlike</a>
</p>
<p>
Built with <a href="http://getpelican.com" target="_blank">Pelican</a> using <a href="http://bit.ly/flex-pelican" target="_blank">Flex</a> theme
</p><p>
<a rel="license"
href="http://creativecommons.org/licenses/by-sa/4.0/"
target="_blank">
<img alt="Creative Commons License"
title="Creative Commons License"
style="border-width:0"
src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"
width="80"
height="15"/>
</a>
</p> </footer>
</main>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Blog",
"name": " Tonychow's Blog ",
"url" : "https://blog.tonychow.me",
"image": "/images/avatar.jpg",
"description": "tonychow's Thoughts and Writings"
}
</script>
</body>
</html>