|
|
@ -316,7 +316,7 @@ if __name__ == '__main__':
|
|||
|
||||
但是,切换作业是有代价的,比如从语文切到数学,要先收拾桌子上的语文书本、钢笔(这叫保存现场),然后,打开数学课本、找出圆规直尺(这叫准备新环境),才能开始做数学作业。操作系统在切换进程或者线程时也是一样的,它需要先保存当前执行的现场环境(CPU寄存器状态、内存页等),然后,把新任务的执行环境准备好(恢复上次的寄存器状态,切换内存页等),才能开始执行。这个切换过程虽然很快,但是也需要耗费时间。如果有几千个任务同时进行,操作系统可能就主要忙着切换任务,根本没有多少时间去执行任务了,这种情况最常见的就是硬盘狂响,点窗口无反应,系统处于假死状态。所以,多任务一旦多到一个限度,反而会使得系统性能急剧下降,最终导致所有任务都做不好。
|
||||
|
||||
是否采用多任务的第二个考虑是任务的类型,可以把任务分为计算密集型和I/O密集型。计算密集型任务的特点是要进行大量的计算,消耗CPU资源,比如对视频进行编码解码或者格式转换等等,这种任务全靠CPU的运算能力,虽然也可以用多任务完成,但是任务越多,花在任务切换的时间就越多,CPU执行任务的效率就越低。计算密集型任务由于主要消耗CPU资源,这类任务用Python这样的脚本语言去执行效率通常很低,最能胜任这类任务的是C语言,我们之前提到了Python中有嵌入C/C++代码的机制。
|
||||
是否采用多任务的第二个考虑是任务的类型,可以把任务分为计算密集型和I/O密集型。计算密集型任务的特点是要进行大量的计算,消耗CPU资源,比如对视频进行编码解码或者格式转换等等,这种任务全靠CPU的运算能力,虽然也可以用多任务完成,但是任务越多,花在任务切换的时间就越多,CPU执行任务的效率就越低。计算密集型任务由于主要消耗CPU资源,这类任务用Python这样的脚本语言去执行效率通常很低,最能胜任这类任务的是C语言,我们之前提到过Python中有嵌入C/C++代码的机制。
|
||||
|
||||
除了计算密集型任务,其他的涉及到网络、存储介质I/O的任务都可以视为I/O密集型任务,这类任务的特点是CPU消耗很少,任务的大部分时间都在等待I/O操作完成(因为I/O的速度远远低于CPU和内存的速度)。对于I/O密集型任务,如果启动多任务,就可以减少I/O等待时间从而让CPU高效率的运转。有一大类的任务都属于I/O密集型任务,这其中包括了我们很快会涉及到的网络应用和Web应用。
|
||||
|
||||
|
|
@ -324,9 +324,9 @@ if __name__ == '__main__':
|
|||
|
||||
### 单线程+异步I/O
|
||||
|
||||
现代操作系统对I/O操作的改进中最为重要的就是支持异步I/O。如果充分利用操作系统提供的异步I/O支持,就可以用单进程单线程模型来执行多任务,这种全新的模型称为事件驱动模型。Nginx就是支持异步I/O的Web服务器,它在单核CPU上采用单进程模型就可以高效地支持多任务。在多核CPU上,可以运行多个进程(数量与CPU核心数相同),充分利用多核CPU。用Node.js开发的服务器端程序也使用了这种工作模式,这也是当下实现多任务编程的一种趋势。
|
||||
现代操作系统对I/O操作的改进中最为重要的就是支持异步I/O。如果充分利用操作系统提供的异步I/O支持,就可以用单进程单线程模型来执行多任务,这种全新的模型称为事件驱动模型。Nginx就是支持异步I/O的Web服务器,它在单核CPU上采用单进程模型就可以高效地支持多任务。在多核CPU上,可以运行多个进程(数量与CPU核心数相同),充分利用多核CPU。用Node.js开发的服务器端程序也使用了这种工作模式,这也是当下并发编程的一种流行方案。
|
||||
|
||||
在Python语言中,单线程+异步I/O的编程模型称为协程,有了协程的支持,就可以基于事件驱动编写高效的多任务程序。协程最大的优势就是极高的执行效率,因为子程序切换不是线程切换,而是由程序自身控制,因此,没有线程切换的开销。协程的第二个优势就是不需要多线程的锁机制,因为只有一个线程,也不存在同时写变量冲突,在协程中控制共享资源不用加锁,只需要判断状态就好了,所以执行效率比多线程高很多。如果想要充分利用CPU的多核特性,最简单的方法是多进程+协程,既充分利用多核,又充分发挥协程的高效率,可获得极高的性能。关于这方面的内容,我稍后会做一个专题来进行讲解。
|
||||
在Python语言中,单线程+异步I/O的编程模型称为协程,有了协程的支持,就可以基于事件驱动编写高效的多任务程序。协程最大的优势就是极高的执行效率,因为子程序切换不是线程切换,而是由程序自身控制,因此,没有线程切换的开销。协程的第二个优势就是不需要多线程的锁机制,因为只有一个线程,也不存在同时写变量冲突,在协程中控制共享资源不用加锁,只需要判断状态就好了,所以执行效率比多线程高很多。如果想要充分利用CPU的多核特性,最简单的方法是多进程+协程,既充分利用多核,又充分发挥协程的高效率,可获得极高的性能。关于这方面的内容,在后续的课程中会进行讲解。
|
||||
|
||||
### 应用案例
|
||||
|
||||
|
|
|
|||
|
|
@ -110,13 +110,70 @@ Pillow中最为重要的是Image类,读取和处理图像都要通过这个类
|
|||
|
||||
### 处理Excel电子表格
|
||||
|
||||
Python的openpyxl模块让我们可以在Python程序中读取和修改Excel电子表格,当然实际工作中,我们可能会用LibreOffice Calc和OpenOffice Calc来处理Excel的电子表格文件,这就意味着openpyxl模块也能处理来自这些软件生成的电子表格。关于openpyxl的使用手册和使用文档可以查看它的[官方文档](https://openpyxl.readthedocs.io/en/stable/#)。
|
||||
Python的openpyxl模块让我们可以在Python程序中读取和修改Excel电子表格,由于微软从Office 2007开始使用了新的文件格式,这使得Office Excel和LibreOffice Calc、OpenOffice Calc是完全兼容的,这就意味着openpyxl模块也能处理来自这些软件生成的电子表格。
|
||||
|
||||
```Python
|
||||
import datetime
|
||||
|
||||
from openpyxl import Workbook
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
ws['A1'] = 42
|
||||
ws.append([1, 2, 3])
|
||||
ws['A2'] = datetime.datetime.now()
|
||||
|
||||
wb.save("sample.xlsx")
|
||||
```
|
||||
|
||||
### 处理Word文档
|
||||
|
||||
利用python-docx模块,Pytho 可以创建和修改Word文档,当然这里的Word文档不仅仅是指通过微软的Office软件创建的扩展名为docx的文档,LibreOffice Writer和OpenOffice Writer都是免费的字处理软件。
|
||||
利用python-docx模块,Python可以创建和修改Word文档,当然这里的Word文档不仅仅是指通过微软的Office软件创建的扩展名为docx的文档,LibreOffice Writer和OpenOffice Writer都是免费的字处理软件。
|
||||
|
||||
```Python
|
||||
from docx import Document
|
||||
from docx.shared import Inches
|
||||
|
||||
### 处理PDF文档
|
||||
document = Document()
|
||||
|
||||
PDF是Portable Document Format的缩写,使用.pdf作为文件扩展名。接下来我们就研究一下如何通过Python实现从PDF读取文本内容和从已有的文档生成新的PDF文件。
|
||||
document.add_heading('Document Title', 0)
|
||||
|
||||
p = document.add_paragraph('A plain paragraph having some ')
|
||||
p.add_run('bold').bold = True
|
||||
p.add_run(' and some ')
|
||||
p.add_run('italic.').italic = True
|
||||
|
||||
document.add_heading('Heading, level 1', level=1)
|
||||
document.add_paragraph('Intense quote', style='Intense Quote')
|
||||
|
||||
document.add_paragraph(
|
||||
'first item in unordered list', style='List Bullet'
|
||||
)
|
||||
document.add_paragraph(
|
||||
'first item in ordered list', style='List Number'
|
||||
)
|
||||
|
||||
document.add_picture('monty-truth.png', width=Inches(1.25))
|
||||
|
||||
records = (
|
||||
(3, '101', 'Spam'),
|
||||
(7, '422', 'Eggs'),
|
||||
(4, '631', 'Spam, spam, eggs, and spam')
|
||||
)
|
||||
|
||||
table = document.add_table(rows=1, cols=3)
|
||||
hdr_cells = table.rows[0].cells
|
||||
hdr_cells[0].text = 'Qty'
|
||||
hdr_cells[1].text = 'Id'
|
||||
hdr_cells[2].text = 'Desc'
|
||||
for qty, id, desc in records:
|
||||
row_cells = table.add_row().cells
|
||||
row_cells[0].text = str(qty)
|
||||
row_cells[1].text = id
|
||||
row_cells[2].text = desc
|
||||
|
||||
document.add_page_break()
|
||||
|
||||
document.save('demo.docx')
|
||||
```
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 515 KiB After Width: | Height: | Size: 412 KiB |
|
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 239 B |
|
Before Width: | Height: | Size: 476 KiB After Width: | Height: | Size: 468 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 180 KiB After Width: | Height: | Size: 171 KiB |
|
|
@ -792,11 +792,11 @@
|
|||
Python使用了自动化内存管理,这种管理机制以**引用计数**为基础,同时也引入了**标记-清除**和**分代收集**两种机制为辅的策略。
|
||||
|
||||
```C
|
||||
typedef struct_object {
|
||||
typedef struct _object {
|
||||
/* 引用计数 */
|
||||
int ob_refcnt;
|
||||
/* 对象指针 */
|
||||
struct_typeobject *ob_type;
|
||||
struct _typeobject *ob_type;
|
||||
} PyObject;
|
||||
```
|
||||
|
||||
|
|
@ -1166,12 +1166,12 @@ Python中实现并发编程的三种方案:多线程、多进程和异步I/O
|
|||
import threading
|
||||
|
||||
|
||||
class Account():
|
||||
class Account:
|
||||
"""银行账户"""
|
||||
|
||||
def __init__(self, balance=0):
|
||||
self.balance = balance
|
||||
lock = threading.Lock()
|
||||
lock = threading.RLock()
|
||||
self.condition = threading.Condition(lock)
|
||||
|
||||
def withdraw(self, money):
|
||||
|
|
@ -1212,9 +1212,10 @@ Python中实现并发编程的三种方案:多线程、多进程和异步I/O
|
|||
|
||||
def main():
|
||||
account = Account()
|
||||
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||
with ThreadPoolExecutor(max_workers=15) as pool:
|
||||
for _ in range(5):
|
||||
pool.submit(add_money, account)
|
||||
for _ in range(10):
|
||||
pool.submit(sub_money, account)
|
||||
|
||||
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 69 KiB |
|
Before Width: | Height: | Size: 330 B After Width: | Height: | Size: 320 B |
|
Before Width: | Height: | Size: 505 B After Width: | Height: | Size: 292 B |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 640 B After Width: | Height: | Size: 582 B |
|
Before Width: | Height: | Size: 474 B After Width: | Height: | Size: 334 B |
|
Before Width: | Height: | Size: 137 KiB After Width: | Height: | Size: 96 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
|
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 309 KiB After Width: | Height: | Size: 291 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 324 B After Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 459 B |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 255 KiB After Width: | Height: | Size: 134 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 395 B After Width: | Height: | Size: 260 B |
|
Before Width: | Height: | Size: 744 B After Width: | Height: | Size: 436 B |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 97 KiB |
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 19 KiB |
|
|
@ -102,7 +102,7 @@
|
|||
// 查询垃圾分类的函数
|
||||
search() {
|
||||
if (this.word.trim().length > 0) {
|
||||
let key = '9636cec76ee2593ba6b195e5b770b394'
|
||||
let key = 'e8c5524dd2a365f20908ced735f8e480'
|
||||
let url = `http://api.tianapi.com/txapi/lajifenlei/?key=${key}&word=${this.word}`
|
||||
fetch(url)
|
||||
.then(resp => resp.json())
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 336 KiB After Width: | Height: | Size: 314 KiB |
|
Before Width: | Height: | Size: 246 KiB After Width: | Height: | Size: 246 KiB |
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 192 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
|
|
@ -136,7 +136,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
|
||||
4. 清除屏幕上显示的内容 - **clear**。
|
||||
|
||||
5. 查看帮助文档 - **man** / **info** / **help** / **apropos**。
|
||||
5. 查看帮助文档 - **man** / **info** / **--help** / **apropos**。
|
||||
```Shell
|
||||
[root@izwz97tbgo9lkabnat2lo8z ~]# ps --help
|
||||
Usage:
|
||||
|
|
@ -230,7 +230,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
[root@iZwz97tbgo9lkabnat2lo8Z ~]# !454
|
||||
```
|
||||
|
||||
> 说明:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令;通过`history -c`可以清除历史命令。
|
||||
> **说明**:查看到历史命令之后,可以用`!历史命令编号`来重新执行该命令;通过`history -c`可以清除历史命令。
|
||||
|
||||
### 实用程序
|
||||
|
||||
|
|
@ -308,7 +308,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
...
|
||||
```
|
||||
|
||||
> 说明:上面用到了一个名为`wget`的命令,它是一个网络下载器程序,可以从指定的URL下载资源。
|
||||
> **说明**:上面用到了一个名为`wget`的命令,它是一个网络下载器程序,可以从指定的URL下载资源。
|
||||
|
||||
6. 拷贝/移动文件 - **cp** / **mv**。
|
||||
|
||||
|
|
@ -350,7 +350,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
52:</script>
|
||||
...
|
||||
```
|
||||
> 说明:`grep`在搜索字符串时可以使用正则表达式,如果需要使用正则表达式可以用`grep -E`或者直接使用`egrep`。
|
||||
> **说明**:`grep`在搜索字符串时可以使用正则表达式,如果需要使用正则表达式可以用`grep -E`或者直接使用`egrep`。
|
||||
|
||||
9. 创建链接和查看链接 - **ln** / **readlink**。
|
||||
|
||||
|
|
@ -372,7 +372,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
CentOS Linux release 7.4.1708 (Core)
|
||||
```
|
||||
|
||||
> 说明:链接可以分为硬链接和软链接(符号链接)。硬链接可以认为是一个指向文件数据的指针,就像Python中对象的引用计数,每添加一个硬链接,文件的对应链接数就增加1,只有当文件的链接数为0时,文件所对应的存储空间才有可能被其他文件覆盖。我们平常删除文件时其实并没有删除硬盘上的数据,我们删除的只是一个指针,或者说是数据的一条使用记录,所以类似于“文件粉碎机”之类的软件在“粉碎”文件时除了删除文件指针,还会在文件对应的存储区域填入数据来保证文件无法再恢复。软链接类似于Windows系统下的快捷方式,当软链接链接的文件被删除时,软链接也就失效了。
|
||||
> **说明**:链接可以分为硬链接和软链接(符号链接)。硬链接可以认为是一个指向文件数据的指针,就像Python中对象的引用计数,每添加一个硬链接,文件的对应链接数就增加1,只有当文件的链接数为0时,文件所对应的存储空间才有可能被其他文件覆盖。我们平常删除文件时其实并没有删除硬盘上的数据,我们删除的只是一个指针,或者说是数据的一条使用记录,所以类似于“文件粉碎机”之类的软件在“粉碎”文件时除了删除文件指针,还会在文件对应的存储区域填入数据来保证文件无法再恢复。软链接类似于Windows系统下的快捷方式,当软链接链接的文件被删除时,软链接也就失效了。
|
||||
|
||||
10. 压缩/解压缩和归档/解归档 - **gzip** / **gunzip** / **xz**。
|
||||
|
||||
|
|
@ -429,7 +429,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
[root@iZwz97tbgo9lkabnat2lo8Z ~]# xargs < a.txt > b.txt
|
||||
```
|
||||
|
||||
> 说明:这个命令就像上面演示的那样常在管道(实现进程间通信的一种方式)和重定向(重新指定输入输出的位置)操作中用到,后面的内容中会讲到管道操作和输入输出重定向操作。
|
||||
> **说明**:这个命令就像上面演示的那样常在管道(实现进程间通信的一种方式)和重定向(重新指定输入输出的位置)操作中用到,后面的内容中会讲到管道操作和输入输出重定向操作。
|
||||
|
||||
13. 显示文件或目录 - **basename** / **dirname**。
|
||||
|
||||
|
|
@ -751,7 +751,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
设置hellokitty用户100天后必须修改密码,过期前15天通知该用户,过期后15天禁用该用户。
|
||||
|
||||
```Shell
|
||||
chage -M 100 -W 15 -I 15 hellokitty
|
||||
chage -M 100 -W 15 -I 7 hellokitty
|
||||
```
|
||||
|
||||
5. 切换用户 - **su**。
|
||||
|
|
@ -954,7 +954,7 @@ Linux系统的命令通常都是如下所示的格式:
|
|||
|
||||
8. 创建/激活/关闭交换分区 - **mkswap** / **swapon** / **swapoff**。
|
||||
|
||||
> 说明:执行上面这些命令会带有一定的风险,如果不清楚这些命令的用法,最好不用随意使用,在使用的过程中,最好对照参考资料进行操作,并在操作前确认是否要这么做。
|
||||
> **说明**:执行上面这些命令会带有一定的风险,如果不清楚这些命令的用法,最好不用随意使用,在使用的过程中,最好对照参考资料进行操作,并在操作前确认是否要这么做。
|
||||
|
||||
### 编辑器 - vim
|
||||
|
||||
|
|
@ -1788,6 +1788,8 @@ echo '结果: '$sum
|
|||
|
||||
```Shell
|
||||
#!/usr/bin/bash
|
||||
printf '输入文件夹名: '
|
||||
read dir
|
||||
printf '输入文件名: '
|
||||
read file
|
||||
printf '输入文件数量(<1000): '
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 220 KiB After Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 190 KiB After Width: | Height: | Size: 179 KiB |
|
|
@ -551,9 +551,9 @@ MySQL在过去由于性能高、成本低、可靠性好,已经成为最流行
|
|||
```SQL
|
||||
-- 插入学院数据
|
||||
insert into tb_college (collname, collintro) values
|
||||
('计算机学院', '创建于1956年是我国首批建立计算机专业。学院现有计算机科学与技术一级学科和网络空间安全一级学科博士学位授予权,其中计算机科学与技术一级学科具有博士后流动站。计算机科学与技术一级学科在2017年全国第四轮学科评估中评为A;2019 U.S.News全球计算机学科排名26名;ESI学科排名0.945‰,进入全球前1‰,位列第43位。'),
|
||||
('外国语学院', '1998年浙江大学、杭州大学、浙江农业大学、浙江医科大学四校合并,成立新的浙江大学。1999年原浙江大学外语系、原杭州大学外国语学院、原杭州大学大外部、原浙江农业大学公外部、原浙江医科大学外语教学部合并,成立浙江大学外国语学院。2003年学院更名为浙江大学外国语言文化与国际交流学院。'),
|
||||
('经济管理学院', '四川大学经济学院历史悠久、传承厚重,其前身是创办于1905年的四川大学经济科,距今已有100多年的历史。已故著名经济学家彭迪先、张与九、蒋学模、胡寄窗、陶大镛、胡代光,以及当代著名学者刘诗白等曾先后在此任教或学习。在长期的办学过程中,学院坚持以马克思主义的立场、观点、方法为指导,围绕建设世界一流经济学院的奋斗目标,做实“两个伟大”深度融合,不断提高党的建设质量与科学推进一流事业深度融合。');
|
||||
('计算机学院', '计算机学院1958年设立计算机专业,1981年建立计算机科学系,1998年设立计算机学院,2005年5月,为了进一步整合教学和科研资源,学校决定,计算机学院和软件学院行政班子合并统一运作、实行教学和学生管理独立运行的模式。 学院下设三个系:计算机科学与技术系、物联网工程系、计算金融系;两个研究所:图象图形研究所、网络空间安全研究院(2015年成立);三个教学实验中心:计算机基础教学实验中心、IBM技术中心和计算机专业实验中心。'),
|
||||
('外国语学院', '四川大学外国语学院设有7个教学单位,6个文理兼收的本科专业;拥有1个一级学科博士授予点,3个二级学科博士授予点,5个一级学科硕士学位授权点,5个二级学科硕士学位授权点,5个硕士专业授权领域,同时还有2个硕士专业学位(MTI)专业;有教职员工210余人,其中教授、副教授80余人,教师中获得中国国内外名校博士学位和正在职攻读博士学位的教师比例占专任教师的60%以上。'),
|
||||
('经济管理学院', '四川大学经济学院前身是创办于1905年的四川大学经济科;已故经济学家彭迪先、张与九、蒋学模、胡寄窗、陶大镛、胡代光,以及当代学者刘诗白等曾先后在此任教或学习;1905年,四川大学设经济科;1924年,四川大学经济系成立;1998年,四川大学经济管理学院变更为四川大学经济学院。');
|
||||
|
||||
-- 插入学生数据
|
||||
insert into tb_student (stuid, stuname, stusex, stubirth, stuaddr, collid) values
|
||||
|
|
@ -836,7 +836,7 @@ possible_keys: NULL
|
|||
|
||||
在上面的SQL执行计划中,有几项值得我们关注:
|
||||
|
||||
1. type:MySQL在表中找到满足条件的行的方式,也称为访问类型,包括:ALL(全表扫描)、index(索引全扫描)、range(索引范围扫描)、ref(非唯一索引扫描)、eq_ref(唯一索引扫描)、const/system、NULL。在所有的访问类型中,很显然ALL是性能最差的,它代表了全表扫描是指要扫描表中的每一行才能找到匹配的行。
|
||||
1. `type`:MySQL在表中找到满足条件的行的方式,也称为访问类型,包括:ALL(全表扫描)、index(索引全扫描)、range(索引范围扫描)、ref(非唯一索引扫描)、eq_ref(唯一索引扫描)、const/system、NULL。在所有的访问类型中,很显然ALL是性能最差的,它代表了全表扫描是指要扫描表中的每一行才能找到匹配的行。
|
||||
2. possible_keys:MySQL可以选择的索引,但是**有可能不会使用**。
|
||||
3. key:MySQL真正使用的索引。
|
||||
4. rows:执行查询需要扫描的行数,这是一个**预估值**。
|
||||
|
|
|
|||