|
@ -32,7 +32,7 @@
|
|||
| \| | 分支 | foo\|bar | 可以匹配foo或者bar |
|
||||
| (?#) | 注释 | | |
|
||||
| (exp) | 匹配exp并捕获到自动命名的组中 | | |
|
||||
| (? <name>exp) | 匹配exp并捕获到名为name的组中 | | |
|
||||
| (?<name>exp) | 匹配exp并捕获到名为name的组中 | | |
|
||||
| (?:exp) | 匹配exp但是不捕获匹配的文本 | | |
|
||||
| (?=exp) | 匹配exp前面的位置 | \\b\\w+(?=ing) | 可以匹配I'm dancing中的danc |
|
||||
| (?<=exp) | 匹配exp后面的位置 | (?<=\\bdanc)\\w+\\b | 可以匹配I love dancing and reading中的第一个ing |
|
||||
|
|
|
@ -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 |
|
@ -147,7 +147,7 @@
|
|||
items = items[:]
|
||||
for i in range(len(items) - 1):
|
||||
swapped = False
|
||||
for j in range(i, len(items) - 1 - i):
|
||||
for j in range(len(items) - 1 - i):
|
||||
if comp(items[j], items[j + 1]):
|
||||
items[j], items[j + 1] = items[j + 1], items[j]
|
||||
swapped = True
|
||||
|
@ -162,7 +162,7 @@
|
|||
items = items[:]
|
||||
for i in range(len(items) - 1):
|
||||
swapped = False
|
||||
for j in range(i, len(items) - 1 - i):
|
||||
for j in range(len(items) - 1 - i):
|
||||
if comp(items[j], items[j + 1]):
|
||||
items[j], items[j + 1] = items[j + 1], items[j]
|
||||
swapped = True
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
## Web前端概述
|
||||
|
||||
> 说明:本文使用的部分插图来自*Jon Duckett*先生的*[HTML and CSS: Design and Build Websites](https://www.amazon.cn/dp/1118008189/ref=sr_1_5?__mk_zh_CN=%E4%BA%9A%E9%A9%AC%E9%80%8A%E7%BD%91%E7%AB%99&keywords=html+%26+css&qid=1554609325&s=gateway&sr=8-5)*一书,这是一本非常棒的前端入门书,有兴趣的读者可以在亚马逊或者其他网站上找到该书的购买链接。
|
||||
> **说明**:本文使用的部分插图来自*Jon Duckett*先生的*[HTML and CSS: Design and Build Websites](https://www.amazon.cn/dp/1118008189/ref=sr_1_5?__mk_zh_CN=%E4%BA%9A%E9%A9%AC%E9%80%8A%E7%BD%91%E7%AB%99&keywords=html+%26+css&qid=1554609325&s=gateway&sr=8-5)*一书,这是一本非常棒的前端入门书,有兴趣的读者可以在亚马逊或者其他网站上找到该书的购买链接。
|
||||
|
||||
### HTML简史
|
||||
|
||||
|
|
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 28 KiB |
|
@ -68,7 +68,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
<div>
|
||||
<input @keydown.enter="addItem()" type="text" id="fname" v-model="fname">
|
||||
<input @keydown.enter="addItem()" type="text" id="fname" v-model.trim="fname">
|
||||
<button id="ok" @click="addItem()">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -82,8 +82,8 @@
|
|||
},
|
||||
methods: {
|
||||
addItem() {
|
||||
if (this.fname.trim().length > 0) {
|
||||
this.fruits.push(this.fname.trim())
|
||||
if (this.fname.length > 0) {
|
||||
this.fruits.push(this.fname)
|
||||
}
|
||||
this.fname = ''
|
||||
},
|
||||
|
|
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 |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 19 KiB |
|
@ -65,7 +65,7 @@
|
|||
<div class="search">
|
||||
<!-- type属性是text的input标签代表文本框 可以接收用户输入 -->
|
||||
<!-- placeholder是文本框的输入提示 -->
|
||||
<input type="text" placeholder="请输入垃圾名字" v-model="word" @keydown.enter="search()">
|
||||
<input type="text" placeholder="请输入垃圾名字" v-model.trim="word" @keydown.enter="search()">
|
||||
<!-- button代表按钮 点击可以开始查询 -->
|
||||
<button @click="search()">查询</button>
|
||||
</div>
|
||||
|
@ -75,9 +75,9 @@
|
|||
<div v-for="result in results">
|
||||
<p>
|
||||
<!-- img是图像标签 可以用来实现图片-->
|
||||
<img :src="pictures[result.type]" width="56" :alt="types[result.type]">
|
||||
<img :src="'images/' + pictures[result.type]" width="56" :alt="types[result.type]">
|
||||
|
||||
<!-- span是跨度标签 代表一个逻辑区域(不分段)-->
|
||||
<!-- span是跨度标签 代表一个逻辑区域-->
|
||||
<span>{{ result.name }}</span>
|
||||
|
||||
<span class="pre" v-if="result.aipre == 1">(预测结果)</span>
|
||||
|
@ -102,7 +102,7 @@
|
|||
// 查询垃圾分类的函数
|
||||
search() {
|
||||
if (this.word.trim().length > 0) {
|
||||
let key = '9aeb28ee8858a167c1755f856f830e22'
|
||||
let key = '9636cec76ee2593ba6b195e5b770b394'
|
||||
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 |