Skip to content

Commit 5f9b9a5

Browse files
committed
更新了部分文档
1 parent ab45ce5 commit 5f9b9a5

25 files changed

+301
-139
lines changed

Day01-15/15.图像和办公文档处理.md

+62-5
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,70 @@ Pillow中最为重要的是Image类,读取和处理图像都要通过这个类
110110

111111
### 处理Excel电子表格
112112

113-
Python的openpyxl模块让我们可以在Python程序中读取和修改Excel电子表格,当然实际工作中,我们可能会用LibreOffice Calc和OpenOffice Calc来处理Excel的电子表格文件,这就意味着openpyxl模块也能处理来自这些软件生成的电子表格。关于openpyxl的使用手册和使用文档可以查看它的[官方文档](https://openpyxl.readthedocs.io/en/stable/#)
113+
Python的openpyxl模块让我们可以在Python程序中读取和修改Excel电子表格,由于微软从Office 2007开始使用了新的文件格式,这使得Office Excel和LibreOffice Calc、OpenOffice Calc是完全兼容的,这就意味着openpyxl模块也能处理来自这些软件生成的电子表格。
114114

115-
### 处理Word文档
115+
```Python
116+
import datetime
116117

117-
利用python-docx模块,Pytho 可以创建和修改Word文档,当然这里的Word文档不仅仅是指通过微软的Office软件创建的扩展名为docx的文档,LibreOffice Writer和OpenOffice Writer都是免费的字处理软件。
118+
from openpyxl import Workbook
118119

120+
wb = Workbook()
121+
ws = wb.active
119122

120-
### 处理PDF文档
123+
ws['A1'] = 42
124+
ws.append([1, 2, 3])
125+
ws['A2'] = datetime.datetime.now()
121126

122-
PDF是Portable Document Format的缩写,使用.pdf作为文件扩展名。接下来我们就研究一下如何通过Python实现从PDF读取文本内容和从已有的文档生成新的PDF文件。
127+
wb.save("sample.xlsx")
128+
```
129+
130+
### 处理Word文档
131+
132+
利用python-docx模块,Python可以创建和修改Word文档,当然这里的Word文档不仅仅是指通过微软的Office软件创建的扩展名为docx的文档,LibreOffice Writer和OpenOffice Writer都是免费的字处理软件。
133+
134+
```Python
135+
from docx import Document
136+
from docx.shared import Inches
137+
138+
document = Document()
139+
140+
document.add_heading('Document Title', 0)
141+
142+
p = document.add_paragraph('A plain paragraph having some ')
143+
p.add_run('bold').bold = True
144+
p.add_run(' and some ')
145+
p.add_run('italic.').italic = True
146+
147+
document.add_heading('Heading, level 1', level=1)
148+
document.add_paragraph('Intense quote', style='Intense Quote')
149+
150+
document.add_paragraph(
151+
'first item in unordered list', style='List Bullet'
152+
)
153+
document.add_paragraph(
154+
'first item in ordered list', style='List Number'
155+
)
156+
157+
document.add_picture('monty-truth.png', width=Inches(1.25))
158+
159+
records = (
160+
(3, '101', 'Spam'),
161+
(7, '422', 'Eggs'),
162+
(4, '631', 'Spam, spam, eggs, and spam')
163+
)
164+
165+
table = document.add_table(rows=1, cols=3)
166+
hdr_cells = table.rows[0].cells
167+
hdr_cells[0].text = 'Qty'
168+
hdr_cells[1].text = 'Id'
169+
hdr_cells[2].text = 'Desc'
170+
for qty, id, desc in records:
171+
row_cells = table.add_row().cells
172+
row_cells[0].text = str(qty)
173+
row_cells[1].text = id
174+
row_cells[2].text = desc
175+
176+
document.add_page_break()
177+
178+
document.save('demo.docx')
179+
```

Day16-20/16-20.Python语言进阶.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,11 @@
792792
Python使用了自动化内存管理,这种管理机制以**引用计数**为基础,同时也引入了**标记-清除****分代收集**两种机制为辅的策略。
793793

794794
```C
795-
typedef struct_object {
795+
typedef struct _object {
796796
/* 引用计数 */
797797
int ob_refcnt;
798798
/* 对象指针 */
799-
struct_typeobject *ob_type;
799+
struct _typeobject *ob_type;
800800
} PyObject;
801801
```
802802
@@ -1166,12 +1166,12 @@ Python中实现并发编程的三种方案:多线程、多进程和异步I/O
11661166
import threading
11671167

11681168

1169-
class Account():
1169+
class Account:
11701170
"""银行账户"""
11711171

11721172
def __init__(self, balance=0):
11731173
self.balance = balance
1174-
lock = threading.Lock()
1174+
lock = threading.RLock()
11751175
self.condition = threading.Condition(lock)
11761176

11771177
def withdraw(self, money):
@@ -1212,9 +1212,10 @@ Python中实现并发编程的三种方案:多线程、多进程和异步I/O
12121212

12131213
def main():
12141214
account = Account()
1215-
with ThreadPoolExecutor(max_workers=10) as pool:
1215+
with ThreadPoolExecutor(max_workers=15) as pool:
12161216
for _ in range(5):
12171217
pool.submit(add_money, account)
1218+
for _ in range(10):
12181219
pool.submit(sub_money, account)
12191220

12201221

Day31-35/31-35.玩转Linux操作系统.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Linux系统的命令通常都是如下所示的格式:
136136

137137
4. 清除屏幕上显示的内容 - **clear**
138138

139-
5. 查看帮助文档 - **man** / **info** / **help** / **apropos**
139+
5. 查看帮助文档 - **man** / **info** / **--help** / **apropos**
140140
```Shell
141141
[root@izwz97tbgo9lkabnat2lo8z ~]# ps --help
142142
Usage:
@@ -1788,6 +1788,8 @@ echo '结果: '$sum
17881788
17891789
```Shell
17901790
#!/usr/bin/bash
1791+
printf '输入文件夹名: '
1792+
read dir
17911793
printf '输入文件名: '
17921794
read file
17931795
printf '输入文件数量(<1000): '

Day36-40/36-38.关系型数据库MySQL.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,9 @@ MySQL在过去由于性能高、成本低、可靠性好,已经成为最流行
551551
```SQL
552552
-- 插入学院数据
553553
insert into tb_college (collname, collintro) values
554-
('计算机学院', '创建于1956年是我国首批建立计算机专业。学院现有计算机科学与技术一级学科和网络空间安全一级学科博士学位授予权,其中计算机科学与技术一级学科具有博士后流动站。计算机科学与技术一级学科在2017年全国第四轮学科评估中评为A;2019 U.S.News全球计算机学科排名26名;ESI学科排名0.945‰,进入全球前1‰,位列第43位'),
555-
('外国语学院', '1998年浙江大学、杭州大学、浙江农业大学、浙江医科大学四校合并,成立新的浙江大学。1999年原浙江大学外语系、原杭州大学外国语学院、原杭州大学大外部、原浙江农业大学公外部、原浙江医科大学外语教学部合并,成立浙江大学外国语学院。2003年学院更名为浙江大学外国语言文化与国际交流学院'),
556-
('经济管理学院', '四川大学经济学院历史悠久、传承厚重,其前身是创办于1905年的四川大学经济科,距今已有100多年的历史。已故著名经济学家彭迪先、张与九、蒋学模、胡寄窗、陶大镛、胡代光,以及当代著名学者刘诗白等曾先后在此任教或学习。在长期的办学过程中,学院坚持以马克思主义的立场、观点、方法为指导,围绕建设世界一流经济学院的奋斗目标,做实“两个伟大”深度融合,不断提高党的建设质量与科学推进一流事业深度融合');
554+
('计算机学院', '计算机学院1958年设立计算机专业,1981年建立计算机科学系,1998年设立计算机学院,2005年5月,为了进一步整合教学和科研资源,学校决定,计算机学院和软件学院行政班子合并统一运作、实行教学和学生管理独立运行的模式。 学院下设三个系:计算机科学与技术系、物联网工程系、计算金融系;两个研究所:图象图形研究所、网络空间安全研究院(2015年成立);三个教学实验中心:计算机基础教学实验中心、IBM技术中心和计算机专业实验中心'),
555+
('外国语学院', '四川大学外国语学院设有7个教学单位,6个文理兼收的本科专业;拥有1个一级学科博士授予点,3个二级学科博士授予点,5个一级学科硕士学位授权点,5个二级学科硕士学位授权点,5个硕士专业授权领域,同时还有2个硕士专业学位(MTI)专业;有教职员工210余人,其中教授、副教授80余人,教师中获得中国国内外名校博士学位和正在职攻读博士学位的教师比例占专任教师的60%以上'),
556+
('经济管理学院', '四川大学经济学院前身是创办于1905年的四川大学经济科;已故经济学家彭迪先、张与九、蒋学模、胡寄窗、陶大镛、胡代光,以及当代学者刘诗白等曾先后在此任教或学习;1905年,四川大学设经济科;1924年,四川大学经济系成立;1998年,四川大学经济管理学院变更为四川大学经济学院');
557557
558558
-- 插入学生数据
559559
insert into tb_student (stuid, stuname, stusex, stubirth, stuaddr, collid) values

Day36-40/code/SRS_create_and_init.sql

+55-54
Original file line numberDiff line numberDiff line change
@@ -2,92 +2,95 @@
22
drop database if exists school;
33

44
-- 创建名为school的数据库并设置默认的字符集和排序方式
5-
create database school default charset utf8 collate utf8_bin;
5+
create database school default charset utf8;
66

77
-- 切换到school数据库上下文环境
88
use school;
99

1010
-- 创建学院表
1111
create table tb_college
1212
(
13-
collid int not null auto_increment comment '编号',
14-
collname varchar(50) not null comment '名称',
15-
collmaster varchar(20) not null comment '院长',
16-
collweb varchar(511) default '' comment '网站',
13+
collid int auto_increment comment '编号',
14+
collname varchar(50) not null comment '名称',
15+
collintro varchar(500) default '' comment '介绍',
1716
primary key (collid)
1817
);
1918

2019
-- 创建学生表
2120
create table tb_student
2221
(
23-
stuid int not null comment '学号',
24-
stuname varchar(20) not null comment '姓名',
25-
stusex bit default 1 comment '性别',
26-
stubirth date not null comment '出生日期',
27-
stuaddr varchar(255) default '' comment '籍贯',
28-
collid int not null comment '所属学院',
22+
stuid int not null comment '学号',
23+
stuname varchar(20) not null comment '姓名',
24+
stusex boolean default 1 comment '性别',
25+
stubirth date not null comment '出生日期',
26+
stuaddr varchar(255) default '' comment '籍贯',
27+
collid int not null comment '所属学院',
2928
primary key (stuid),
3029
foreign key (collid) references tb_college (collid)
3130
);
3231

33-
-- alter table tb_student add constraint fk_student_collid foreign key (collid) references tb_college (collid);
34-
3532
-- 创建教师表
3633
create table tb_teacher
3734
(
38-
teaid int not null comment '工号',
39-
teaname varchar(20) not null comment '姓名',
40-
teatitle varchar(10) default '助教' comment '职称',
41-
collid int not null comment '所属学院',
35+
teaid int not null comment '工号',
36+
teaname varchar(20) not null comment '姓名',
37+
teatitle varchar(10) default '助教' comment '职称',
38+
collid int not null comment '所属学院',
4239
primary key (teaid),
4340
foreign key (collid) references tb_college (collid)
4441
);
4542

4643
-- 创建课程表
4744
create table tb_course
4845
(
49-
couid int not null comment '编号',
50-
couname varchar(50) not null comment '名称',
51-
coucredit int not null comment '学分',
52-
teaid int not null comment '授课老师',
46+
couid int not null comment '编号',
47+
couname varchar(50) not null comment '名称',
48+
coucredit int not null comment '学分',
49+
teaid int not null comment '授课老师',
5350
primary key (couid),
5451
foreign key (teaid) references tb_teacher (teaid)
5552
);
5653

5754
-- 创建选课记录表
58-
create table tb_score
55+
create table tb_record
5956
(
60-
scid int auto_increment comment '选课记录编号',
61-
stuid int not null comment '选课学生',
62-
couid int not null comment '所选课程',
63-
scdate datetime comment '选课时间日期',
64-
scmark decimal(4,1) comment '考试成绩',
65-
primary key (scid),
66-
foreign key (stuid) references tb_student (stuid),
67-
foreign key (couid) references tb_course (couid)
57+
recid int auto_increment comment '选课记录编号',
58+
sid int not null comment '选课学生',
59+
cid int not null comment '所选课程',
60+
seldate datetime default now() comment '选课时间日期',
61+
score decimal(4,1) comment '考试成绩',
62+
primary key (recid),
63+
foreign key (sid) references tb_student (stuid),
64+
foreign key (cid) references tb_course (couid),
65+
unique (sid, cid)
6866
);
6967

70-
-- 添加唯一性约束(一个学生选某个课程只能选一次)
71-
alter table tb_score add constraint uni_score_stuid_couid unique (stuid, couid);
72-
7368
-- 插入学院数据
74-
insert into tb_college (collname, collmaster, collweb) values
75-
('计算机学院', '左冷禅', 'http://www.abc.com'),
76-
('外国语学院', '岳不群', 'http://www.xyz.com'),
77-
('经济管理学院', '风清扬', 'http://www.foo.com');
69+
insert into tb_college (collname, collintro) values
70+
('计算机学院', '计算机学院1958年设立计算机专业,1981年建立计算机科学系,1998年设立计算机学院,2005年5月,为了进一步整合教学和科研资源,学校决定,计算机学院和软件学院行政班子合并统一运作、实行教学和学生管理独立运行的模式。 学院下设三个系:计算机科学与技术系、物联网工程系、计算金融系;两个研究所:图象图形研究所、网络空间安全研究院(2015年成立);三个教学实验中心:计算机基础教学实验中心、IBM技术中心和计算机专业实验中心。'),
71+
('外国语学院', '四川大学外国语学院设有7个教学单位,6个文理兼收的本科专业;拥有1个一级学科博士授予点,3个二级学科博士授予点,5个一级学科硕士学位授权点,5个二级学科硕士学位授权点,5个硕士专业授权领域,同时还有2个硕士专业学位(MTI)专业;有教职员工210余人,其中教授、副教授80余人,教师中获得中国国内外名校博士学位和正在职攻读博士学位的教师比例占专任教师的60%以上。'),
72+
('经济管理学院', '四川大学经济学院前身是创办于1905年的四川大学经济科;已故经济学家彭迪先、张与九、蒋学模、胡寄窗、陶大镛、胡代光,以及当代学者刘诗白等曾先后在此任教或学习;1905年,四川大学设经济科;1924年,四川大学经济系成立;1998年,四川大学经济管理学院变更为四川大学经济学院。');
7873

7974
-- 插入学生数据
80-
insert into tb_student (stuid, stuname, stusex, stubirth, stuaddr, collid) values
81-
(1001, '杨逍', 1, '1990-3-4', '四川成都', 1),
82-
(1002, '任我行', 1, '1992-2-2', '湖南长沙', 1),
83-
(1033, '王语嫣', 0, '1989-12-3', '四川成都', 1),
84-
(1572, '岳不群', 1, '1993-7-19', '陕西咸阳', 1),
85-
(1378, '纪嫣然', 0, '1995-8-12', '四川绵阳', 1),
86-
(1954, '林平之', 1, '1994-9-20', '福建莆田', 1),
87-
(2035, '东方不败', 1, '1988-6-30', null, 2),
88-
(3011, '林震南', 1, '1985-12-12', '福建莆田', 3),
89-
(3755, '项少龙', 1, '1993-1-25', null, 3),
90-
(3923, '杨不悔', 0, '1985-4-17', '四川成都', 3);
75+
insert into tb_student (stuid, stuname, stusex, stubirth, stuaddr, collid)
76+
values
77+
(1001, '杨逍', 1, '1990-3-4', '四川成都', 1),
78+
(1002, '任我行', 1, '1992-2-2', '湖南长沙', 1),
79+
(1033, '王语嫣', 0, '1989-12-3', '四川成都', 1),
80+
(1572, '岳不群', 1, '1993-7-19', '陕西咸阳', 1),
81+
(1378, '纪嫣然', 0, '1995-8-12', '四川绵阳', 1),
82+
(1954, '林平之', 1, '1994-9-20', '福建莆田', 1),
83+
(2035, '东方不败', 1, '1988-6-30', null, 2),
84+
(3011, '林震南', 1, '1985-12-12', '福建莆田', 3),
85+
(3755, '项少龙', 1, '1993-1-25', null, 3),
86+
(3923, '杨不悔', 0, '1985-4-17', '四川成都', 3),
87+
(4040, '炼腰的隔壁老王', 1, '1989-1-1', '四川成都', 2);
88+
89+
-- 删除学生数据
90+
delete from tb_student where stuid=4040;
91+
92+
-- 更新学生数据
93+
update tb_student set stuname='杨过', stuaddr='湖南长沙' where stuid=1001;
9194

9295
-- 插入老师数据
9396
insert into tb_teacher (teaid, teaname, teatitle, collid) values
@@ -110,7 +113,7 @@ insert into tb_course (couid, couname, coucredit, teaid) values
110113
(9999, '审计学', 3, 3366);
111114

112115
-- 插入选课数据
113-
insert into tb_score (stuid, couid, scdate, scmark) values
116+
insert into tb_record (sid, cid, seldate, score) values
114117
(1001, 1111, '2017-09-01', 95),
115118
(1001, 2222, '2017-09-01', 87.5),
116119
(1001, 3333, '2017-09-01', 100),
@@ -125,9 +128,9 @@ insert into tb_score (stuid, couid, scdate, scmark) values
125128
(1378, 1111, '2017-09-05', 82),
126129
(1378, 7777, '2017-09-02', 65.5),
127130
(2035, 7777, '2018-09-03', 88),
128-
(2035, 9999, curdate(), null),
129-
(3755, 1111, date(now()), null),
130-
(3755, 8888, date(now()), null),
131+
(2035, 9999, default, null),
132+
(3755, 1111, default, null),
133+
(3755, 8888, default, null),
131134
(3755, 9999, '2017-09-01', 92);
132135

133136
-- 查询所有学生信息
@@ -227,8 +230,6 @@ select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.
227230

228231
select stuname, couname, scmark from tb_student t1 inner join tb_score t3 on t1.stuid=t3.stuid inner join tb_course t2 on t2.couid=t3.couid where scmark is not null order by scmark desc limit 10, 5;
229232

230-
-- 单表:65535TB
231-
-- 单列:4G - LONGBLOB (Binary Large OBject) / LONGTEXT
232233
-- 查询选课学生的姓名和平均成绩(子查询和连接查询)
233234
select stuname, avgmark from tb_student t1, (select stuid, avg(scmark) as avgmark from tb_score group by stuid) t2 where t1.stuid=t2.stuid;
234235

Day41-55/42.深入模型.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@
132132
class Meta:
133133
managed = False
134134
db_table = 'tb_subject'
135-
verbose_name = '学科'
136-
verbose_name_plural = '学科'
137135

138136

139137
class Teacher(models.Model):
@@ -151,7 +149,7 @@
151149
managed = False
152150
db_table = 'tb_teacher'
153151
```
154-
152+
155153
> **说明**:模型类都直接或间接继承自`Model`类,模型类跟关系型数据库的二维表对应,模型对象跟表中的记录对应,模型对象的属性跟表中的字段对应。如果对上面模型类的属性定义不是特别理解,可以看看本文后面提供的“模型定义参考”部分的内容。
156154
157155
### 使用ORM完成模型的CRUD操作
@@ -205,6 +203,8 @@ Subject.objects.filter(name='Python全栈+人工智能')
205203

206204
# 查询名称包含“全栈”的学科(模糊查询)
207205
Subject.objects.filter(name__contains='全栈')
206+
Subject.objects.filter(name__startswith='全栈')
207+
Subject.objects.filter(name__endswith='全栈')
208208

209209
# 查询所有热门学科
210210
Subject.objects.filter(is_hot=True)
@@ -513,7 +513,7 @@ Teacher.objects.filter(subject__name__contains='全栈')
513513
<div>
514514
<span><strong>姓名:{{ teacher.name }}</strong></span>
515515
<span>性别:{{ teacher.sex | yesno:'男,女' }}</span>
516-
<span>出生日期:{{ teacher.birth }}</span>
516+
<span>出生日期:{{ teacher.birth | date:'Y年n月j日'}}</span>
517517
</div>
518518
<div class="intro">{{ teacher.intro }}</div>
519519
<div class="comment">

Day41-55/45.制作报表.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
报表 = 多样的格式 + 动态的数据
99
```
1010

11-
有很多的三方库支持在Python程序中写Excel文件,包括[`xlwt`](<https://xlwt.readthedocs.io/en/latest/>)[`xlwings`](<https://docs.xlwings.org/en/latest/quickstart.html>)[`openpyxl`](<https://openpyxl.readthedocs.io/en/latest/>)[`xlswriter`](<https://xlsxwriter.readthedocs.io/>)[`pandas`](<http://pandas.pydata.org/>)等,其中的xlwt虽然只支持写xls格式的Excel文件,但在性能方面的表现还是不错的。下面我们就以`xlwt`为例,来演示如何在Django项目中导出Excel报表。
11+
有很多的三方库支持在Python程序中写Excel文件,包括[`xlwt`](<https://xlwt.readthedocs.io/en/latest/>)[`xlwings`](<https://docs.xlwings.org/en/latest/quickstart.html>)[`openpyxl`](<https://openpyxl.readthedocs.io/en/latest/>)[`xlswriter`](<https://xlsxwriter.readthedocs.io/>)等,其中的xlwt虽然只支持写xls格式的Excel文件,但在性能方面的表现还是不错的。下面我们就以`xlwt`为例,来演示如何在Django项目中导出Excel报表。
1212

1313
安装`xlwt`
1414

Day41-55/48.前后端分离开发入门.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,5 @@ class SubjectMapper(ModelMapper):
174174

175175
前后端分离的开发需要将前端页面作为静态资源进行部署,项目实际上线的时候,我们会对整个Web应用进行动静分离,静态资源通过Nginx或Apache服务器进行部署,生成动态内容的Python程序部署在uWSGI或者Gunicorn服务器上,对动态内容的请求由Nginx或Apache路由到uWSGI或Gunicorn服务器上。
176176

177-
在开发阶段,我们通常会使用Django自带的测试服务器,如果要尝试前后端分离,可以先将静态页面放在之前创建的放静态资源的目录下,具体的做法可以参考[项目完整代码](https://gitee.com/jackfrued/django19062)
177+
在开发阶段,我们通常会使用Django自带的测试服务器,如果要尝试前后端分离,可以先将静态页面放在之前创建的放静态资源的目录下,具体的做法可以参考[项目完整代码](https://gitee.com/jackfrued/django19062)
178+

0 commit comments

Comments
 (0)