diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..cff2022 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +flypython.com \ No newline at end of file diff --git a/archives/2018/01/index.html b/archives/2018/01/index.html new file mode 100644 index 0000000..20e125d --- /dev/null +++ b/archives/2018/01/index.html @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/archives/2018/index.html b/archives/2018/index.html new file mode 100644 index 0000000..20e125d --- /dev/null +++ b/archives/2018/index.html @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/archives/2019/01/index.html b/archives/2019/01/index.html new file mode 100644 index 0000000..b54e0c4 --- /dev/null +++ b/archives/2019/01/index.html @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/archives/2019/02/index.html b/archives/2019/02/index.html new file mode 100644 index 0000000..fe84656 --- /dev/null +++ b/archives/2019/02/index.html @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/archives/2019/03/index.html b/archives/2019/03/index.html new file mode 100644 index 0000000..fb0c517 --- /dev/null +++ b/archives/2019/03/index.html @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/archives/2019/04/index.html b/archives/2019/04/index.html new file mode 100644 index 0000000..bacc975 --- /dev/null +++ b/archives/2019/04/index.html @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/archives/2019/index.html b/archives/2019/index.html new file mode 100644 index 0000000..5edaea2 --- /dev/null +++ b/archives/2019/index.html @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/archives/index.html b/archives/index.html new file mode 100644 index 0000000..30e9105 --- /dev/null +++ b/archives/index.html @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/article/about/index.html b/article/about/index.html new file mode 100644 index 0000000..c0db6df --- /dev/null +++ b/article/about/index.html @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 关于我们 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

关于我们

+
+ Author:flypython | Date: 2018-01-01 | Category:Python入门 +
+
+
+
+
+

关于我们

http://flypython.com

+

关于FlyPython

FlyPython是提供一站式Python编程学习的组织,我们致力于为用户提供高效,有趣的学习环境,打造专注于Python的中文学习社区。

+

联系我们

客服&合作: 微信号 flypython

+

公众号二维码

FlyPython

+

FlyPython训练营

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-new-01/index.html b/article/python-new-01/index.html new file mode 100644 index 0000000..c1d15f0 --- /dev/null +++ b/article/python-new-01/index.html @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python 3.8新特性——赋值表达式 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python 3.8新特性——赋值表达式

+
+ Author:flypython | Date: 2019-04-01 | Category:Python新特性 +
+
+
+
+
+

上周,Python3.8版本发布,到底带来了哪些新的特性呢?我们应该在哪些场景中使用这些特性呢?本周,我们通过几篇文章来告诉你答案。

+

+

安装

首先,我们并不推荐安装最新版本到常用的开发环境中,你可以使用虚拟环境或者docker来尝鲜。

+

官方安装包

+

网址:https://www.python.org/downloads/release/python-380/

+

也可以使用docker

+

拉取镜像命令
docker pull python:3.8

+

赋值表达式

+

赋值表达式被叫做海象运算符,因为它的形状像海象。如果熟悉go语言的话,会对这个表达式会熟悉。

+

赋值表达式的语法是

+
1
name := expression
+ +

和赋值语句 = 作用差不多,非必不可少,但可以简化代码。

+

官方示例

1
2
3
4
5
>>> a = False
>>> print(a)
False
>>> print(a := True)
True
+ +

此例子赋值之后,后续还需要使用变量。赋值表达可用于简化代码,提高可读性。

+
1
2
3
4
5
6
7
8
9
10
11
12
13
>>> inputs = list()
>>> while True:
... current = input("your input:")
... if current == "quit":
... break
... inputs.append(current)
...
your input:a
your input:b
your input:test
your input:quit
>>> inputs
['a', 'b', 'test']
+ +

使用赋值操作符时:

+
1
2
3
4
5
6
7
8
9
10
>>> inputs = list()
>>> while (current := input("your input:")) != "quit":
... inputs.append(current)
...
your input:a
your input:b
your input:test
your input:quit
>>> inputs
['a', 'b', 'test']
+ +

此例子,省略了一条语句,可读性上升。

+

再来一个例子

+

最初版本

+
1
2
3
a = [1,2,3,4]
if len(a) > 3: #计算 len(a) 一次
print(f"a is too long ({len(a)} elements,expected < 3)") # 计算 len(a) 第二次
+ +

我们改写为:

+

改进版本

+
1
2
3
4
a = [1,2,3,4]
n = len(a) # 计算一次len(a)
if n > 3: # 多了变量n
print(f"a is too long ({n} elements,expected < 3)") #
+ +

新特性重写:
重写版本

+
1
2
3
a = [1,2,3,4]
if (n:=len(a)) > 3: # 计算一次len(a),多了变量n,把两行改为一行
print(f"a is too long ({n} elements,expected < 3)") #
+ +

从上面可以看到,重写版本和改进版本的不同在于:

+
1
2
3
n = len(a) 
if n > 3:
pass
+ + +

+
1
2
if (n:=len(a)) > 3:
pass
+ +

这两个版本的区别在于,:==是补充关系并不是替换关系,下面的例子可以看到官方的意图。

+
1
2
3
4
5
6
7
8
9
x = 5
print(f"x = {x}")

#能用=解决的就用=解决
y := 5 # SyntaxError: invalid syntax
print(f"y = {y}")

(z := 5)
print(f"z = {z}")
+ +

由上面可以看出:==是互补关系,在应该使用:=的时候才可以使用:=

+

Python语言的一致性,不管是专家还是新手,在同一个问题上都应该有一致的写法,然后这就形成了最pythonic的写法。

+

最后带来,新特性带来的最佳实践

+
1
2
3
4
5
6
7
8
9
# 简化 os.fork 
if pid := os.fork():
# Parent code
else:
# Child code

# 直接到把 socket 对象的 read buffer 读完为止
while data := sock.recv(8192):
print("Received data:", data)
+ +

参考

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-new-02/index.html b/article/python-new-02/index.html new file mode 100644 index 0000000..aa12759 --- /dev/null +++ b/article/python-new-02/index.html @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python 3.8新特性——仅限位置形参 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python 3.8新特性——仅限位置形参

+
+ Author:flypython | Date: 2019-04-02 | Category:Python新特性 +
+
+
+
+
+

仅限位置形参

Positional-only parameters官方翻译为仅限位置形参,也可以理解为只接受位置参数。意思就是,它只是一个位置参数,不接受关键字传参。

+

语法:

+
1
2
def funx(a,b,/): # / 指明,前面的a,b参数是仅限位置形参
pass
+ +

函数形参语法/ 用来指明某些函数形参必须使用仅限位置而非关键字参数

+

其实,Python内置的很多C函数接口都是这种形式,比如

+
1
2
3
4
5
6
>>> import builtins
>>> help(__builtins__.divmod)
Help on built-in function divmod in module builtins:

divmod(x, y, /)
Return the tuple (x//y, x%y). Invariant: div*y + mod == x.
+ +

很多函数后面都有 /来表明,左边的这些参数只接受位置参数。

+
1
2
3
4
5
6
7
>>> divmod(1,2)
(0, 1)
>>> divmod(x=1,y=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: divmod() takes no keyword arguments
>>>
+ +

指定关键字的参数会报语法错误,它的用途就是强制使用者用位置参数来传参。

+

官方例子

1
2
3
4
5
>>> def f(a,b,/,**kwargs):
... print(a,b,kwargs)
...
>>> f(10,20,a=1,b=2,c=3)
10 20 {'a': 1, 'b': 2, 'c': 3}
+ +

由于在 / 左侧的形参不会被公开为可用关键字

+

这里的a,b 为仅限位置参数,最后a,b会被赋值了两次。
位置参数赋值一次,关键字参数赋值一次,关键字参数以kwargs字典的形式存在,需要通过 kwargs['a'],kwargs['b']访问。

+

现在我们来看一下,添加了仅限位置形参之后的函数参数形式

+
1
2
def name(positional_only_parameters, /, positional_or_keyword_parameters,
*, keyword_only_parameters):
+ +

包括了仅限位置形参, /, 位置形参或者关键字参数 ,*,仅限关键字参数。

+

+

最后,我们可以定义以下形式的函数

+
1
2
3
4
5
6
def name(p1, p2, /, p_or_kw, *, kw):
def name(p1, p2=None, /, p_or_kw=None, *, kw):
def name(p1, p2=None, /, *, kw):
def name(p1, p2=None, /):
def name(p1, p2, /, p_or_kw):
def name(p1, p2, /):
+ +

参考

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-nlp-01/index.html b/article/python-nlp-01/index.html new file mode 100644 index 0000000..b01050f --- /dev/null +++ b/article/python-nlp-01/index.html @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 使用 Python 生成《红楼梦》词云 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

使用 Python 生成《红楼梦》词云

+
+ Author:flypython | Date: 2019-03-01 | Category:自然语言处理 +
+
+
+
+
+

使用 Python 生成《红楼梦》词云

+

+

本文介绍如何使用python绘制《红楼梦》的词云。

+
+

“词云”就是对网络文本中出现频率较高的“关键词”予以视觉上的突出,形成“关键词云层”或“关键词渲染”,从而过滤掉大量的文本信息,使浏览网页者只要一眼扫过文本就可以领略文本的主旨。
“词云”——网络内容发布新招式 .人民网

+
+

0.摘要

本文建议在电脑上打开,边阅读边操作。

+
    +
  1. 安装python词云工具wordcloud,画图软件matplotlib
  2. +
  3. 准备红楼梦文本
  4. +
  5. 编写python代码并运行
  6. +
  7. 展示词云结果
  8. +
+

1.安装wordcloud

可以在cmd窗口输入

install wordcloud matplotlib```
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

![](http://jcjview.github.io/img/wordcloud001.png)


## 2.准备红楼梦文本

文本可以用下面链接下载


`https://github.com/flypythoncom/flypython/blob/master/wordcloud_hlm_seg.txt`

或者可以自己写代码,对文本进行清洗,分词。
这里需要安装jieba分词,`pip install jieba`
``` python
import jieba
import re

special_character_removal = re.compile(r'[,。、【 】“”:;()《》‘’{}?!⑦%>℃.^-——=&#@¥『』]', re.IGNORECASE)

fw=open("hlm_seg.txt","w",encoding="utf-8")

with open('hlm.txt',encoding="utf-8") as fp:
for line in fp:
l = special_character_removal.sub('', line.strip())
words=jieba.cut(l)
t=" ".join(words)
fw.write(t)
fw.write("\n")

fw.close()

+

3. 编写词云python代码并运行

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
from os import path  
from wordcloud import WordCloud

d = path.dirname(__file__)
# Read the whole text.
text = open(path.join(d, 'hlm_seg.txt'),encoding="utf-8").read()
# Generate a word cloud image
# font=path.join(d, "simkai.ttf")
font='C:/Windows/Fonts/simkai.ttf'
wordcloud = WordCloud(font_path=font,#设置中文字体,不指定就会出现中文不显示
width=1024,#宽
height=840,#高
background_color='white',#设置背景色
# max_words=100,#最大词汇数
# max_font_size=100#最大号字体
).generate(text)

# Display the generated image:
# the matplotlib way:
import matplotlib.pyplot as plt

plt.figure()
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
+ +

结果:

+

词云运行结果

+

后台回复“词云”获得完整运行代码

+

人生苦短,我用python早下班。如果觉得不错,对你工作中有帮助,请加我微信公众号flypython,我们一起探讨python相关问题

+

flypython微信公众号

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-oa-01/index.html b/article/python-oa-01/index.html new file mode 100644 index 0000000..b36a9f6 --- /dev/null +++ b/article/python-oa-01/index.html @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python写入Excel表格 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python写入Excel表格

+
+ Author:flypython | Date: 2019-01-01 | Category:自动化办公 +
+
+
+
+
+

【极简Python 自动化办公】Python写入Excel表格

+

【极简Python 自动化办公】专栏是介绍如何利用python办公,减少工作负荷。篇幅精炼,内容易懂,无论是否有编程基础,都非常适合。

+
+

在上次文章中,我们学习了【用python读取excel】,这次我们继续学习Python写excel吧!

+

+

0.摘要

本文大约需要15分钟,建议在电脑上打开,边阅读边操作。

+
    +
  1. 安装Python读excel模块——xlwt
  2. +
  3. 准备写入表格内容
  4. +
  5. 编写python代码并运行
  6. +
  7. 使用for循环语句读取并写入excel表格
  8. +
+

1.安装xlwt

与上篇文章类似,需要在cmd窗口输入

install xlwt```。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
![](http://jcjview.github.io/img/flypythonpythonexcelw2.png)

## 2.准备写入表格内容

这步很简单,只要想好输入内容即可,这里设计了一个简单的表格内容作为写入内容(目前这个内容还不存在)。

| 序号  | 学号 |年龄 |
| --- | --- |--- |
| 张三 | 20190901 |11|
| 李四 |20190902|12 |
| 小明 | 20190903 |13 |

## 3.编写python代码并运行

新建一个writeexcel.py文件,用记事本或其他文本编辑工具打开。

本次写入excel的思路是,新建文件->指定行列->写入内容。

在文本编辑工具中输入如下代码,保存并关闭。

+

import xlwt

+

f = xlwt.Workbook()
sheet1 = f.add_sheet(‘sheet1’,cell_overwrite_ok=True)
column = [“姓名”,”学号”,”年龄”]
name = [“张三”,”李四”,”小明”]

+

school_code = [20190901,20190902,20190903]

+

age = [11,12,13]

+

sheet1.write(0,0,column[0])#第1行第1列
sheet1.write(0,1,column[1])#第3行第3列
sheet1.write(0,2,column[2])#第2行第2列

+

sheet1.write(1,0,name[0])#第2行第1列
sheet1.write(1,1,school_code[0])#第2行第1列
sheet1.write(1,2,age[0])#第3行第1列

+

sheet1.write(2,0,name[1])
sheet1.write(2,1,school_code[1])
sheet1.write(2,2,age[1])

+

sheet1.write(3,0,name[2])
sheet1.write(3,1,school_code[2])
sheet1.write(3,2,age[2])

+

f.save(‘test1.xls’)

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

还是一样,注意每句的开头不可以有空格,因为python用*缩进*来表示编程的层次,缩进不同就会报错了。


在保存writeexcel.py的位置上打开cmd,运行 python writeexcel.py
可以看到结果:
![](http://jcjview.github.io/img/flypythonpythonexcelw4.png)
![](http://jcjview.github.io/img/flypythonpythonexcelw5.png)


## 4.使用for循环语句读取并写入excel表格

非常好!您已经学会了如何读取和写入excel表格。

但是,我们只能一个一个单元格读取和写入数据,这比手工操作excel表格快不了多少。

接下来,我们需要学习使用for循环,来批量读取一个excel表格,并循环写入另一个excel表格中。

不要删除test1.xls,在test1.xls文件的位置,新建一个rwexcel.py文件,将下面代码输入到文件中:
+ +

import xlrd
import xlwt

+

wb = xlrd.open_workbook(“test1.xls”)#打开文件
sheet1 = wb.sheet_by_index(0)#获取第一个表格

+

column = []#列名

+

data=[]

+

#获取列名
column.append(sheet1.cell(0,0).value)#姓名
column.append(sheet1.cell(0,1).value)#学号
column.append(sheet1.cell(0,2).value)#年龄

+

for i in range(1,sheet1.nrows):#sheet1.nrows 行数
coldata=[]
coldata.append(sheet1.cell(i, 0).value)#姓名
coldata.append(int(sheet1.cell_value(i, 1)))#学号
coldata.append(sheet1.cell(i, 2).value)#年龄
data.append(coldata)

+

f = xlwt.Workbook()
sheetw = f.add_sheet(‘sheet1’,cell_overwrite_ok=True)

+

sheetw.write(0,0,column[0])#姓名
sheetw.write(0,2,column[2])#学号
sheetw.write(0,1,column[1])#年龄

+

for i in range(len(data)):
d=data[i]
sheetw.write(i+1, 0, d[0]) # 第2行第1列
sheetw.write(i+1, 1, d[1]) # 第2行第1列
sheetw.write(i+1, 2, d[2]) # 第3行第1列

+

f.save(‘test2.xls’)

+

```

+

运行后,会生成一个test2.xls,与test1.xls一模一样。

+

人生苦短,我用python早下班。如果觉得不错,对你工作中有帮助,请加我微信公众号flypython,我们一起探讨python相关问题

+

flypython微信公众号

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-oa-02/index.html b/article/python-oa-02/index.html new file mode 100644 index 0000000..c86cf43 --- /dev/null +++ b/article/python-oa-02/index.html @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python写入Word文档 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python写入Word文档

+
+ Author:flypython | Date: 2019-01-02 | Category:自动化办公 +
+
+
+
+
+
+

【极简Python 自动化办公】专栏是介绍如何利用python办公,减少工作负荷。篇幅精炼,内容易懂,无论是否有编程基础,都非常适合。

+
+

在上次文章中,我们学习了【用python写入excel】,这次我们学习Python写word文档吧!

+

场景:
有时候,办公室需要按模版生成的固定的文件,模板是固定的,只是每次需要替换信息。如下图的收入证明,模版中所有标黄的都是需要替换的信息:

如果手工来做这个事情,每次至少需要10分钟的时间。假如每天要开15份,则至少要花2个半小时,而且手工编辑word很容易出错。

+

可不可用python写个程序,解决这个问题呢?

+

结论当然是肯定的!

+

0.摘要

本文大约需要15分钟,建议在电脑上打开,边阅读边操作。

+
    +
  1. 安装Python读写word模块,python-docx
  2. +
  3. 准备word模板,准备写入word文档内容
  4. +
  5. 编写python代码并运行
  6. +
  7. 通过读取excel表格中的信息,批量生成word文件
  8. +
+

1.安装python-docx模块

与上篇文章类似,需要在cmd窗口输入pip install python-docx

+

2.准备word模板,准备写入word文档内容

word模板如上所示,(可以不需要标黄),这里注意,需要替换的文字或数字位置,用”XXXX”来固定替代。保存为个人收入证明.docx

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
名称内容
姓名张三
身份证号104111199009103531
职务工程师
工作年限10
月收入10000
大写壹万元整
联系人李四
单位名称格物致知股份有限公司
单位地址珠海市横琴新区宝华路6号105室-67425
联系电话0756-8627528
+

3. 编写python代码并运行

在word模板的同级目录,新建一个writeword.py文件,用记事本或其他文本编辑工具打开。

+

编程思路:

+
    +
  1. 用python打开对应doc模板
  2. +
  3. 按顺序找到每一个需要替换的位置字符”XXXX”,替换为对应的内容
  4. +
  5. 另存为doc为另一个文件
  6. +
+

在文本编辑工具中输入如下代码,保存并关闭。

+
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
from docx import Document
#准备写入内容
name="张三"
id_code="104111199009103531"
career="工程师"
working_years="10"
salary="10000"
salary_uppercase="壹万元整"
contact="李四"
company="格物厚德股份有限公司"
address="珠海市横琴新区宝华路6号105室-67425"
tel="0756-8627528"
#打开doc

textlist=[name,id_code,career,working_years,salary,salary_uppercase,company,address,contact,tel]

doc = Document("个人收入证明.docx")

count=0

for p in doc.paragraphs:
        if 'XXXX' in p.text:
            inline = p.runs
            for i in range(len(inline)):
                if 'XXXX' in inline[i].text:
                    text = inline[i].text.replace('XXXX', textlist[count])
                    inline[i].text = text
                    count+=1
                    print(count)
doc.save("%s_个人收入证明.docx"%name)
+ +

在同级目录,打开cmd,运行writeword.py python writeword.py

+

生成结果如下:
张三_个人收入证明.docx

+

4.通过读取excel表格中的信息,批量生成word文件

这里生成了对应word文件,但也有几个问题:

+
    +
  1. 对应的日期并没有自动填写,应当填写文件生成时对应的日期
  2. +
  3. 如果是生成大量同样word文档的话,目前的程序也需要一个一个改,并没有提升太多效率
  4. +
+

如果您看过我们之前的2篇用python读写excel的文章,您肯定就会想到,可以利用读取excel表格里的内容,批量生成对应的word文档。对,让我们继续吧!

+

这里再准备一个excel文件,将需要批量写入的信息写在excel中,并保存为income.xlsx在同级目录,如下图:

+

+

修改python 文件writeword.py

+
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
from docx import Document
#准备写入内容
import xlrd
import time
# 当前时间元组
from datetime import datetime
nt=datetime.now()
# 可以输入中文年月日
datestr=nt.strftime('%Y{y}%m{m}%d{d}').format(y='年', m='月', d='日')

xlsx=xlrd.open_workbook('income.xlsx')
sheet=xlsx.sheet_by_index(0)
for row in range(1,sheet.nrows):
    doc = Document("个人收入证明.docx")
    count=0
    textlist=[]
    for col in range(0,sheet.ncols):
        textlist.append(str(sheet.cell_value(row, col)))

    for p in doc.paragraphs:
            if 'XXXX' in p.text:
                inline = p.runs
                for i in range(len(inline)):
                    if 'XXXX' in inline[i].text:
                        text = inline[i].text.replace('XXXX', textlist[count])
                        inline[i].text = text
                        count+=1
            if 'X 年   X 月  X 日' in p.text:
                inline = p.runs
                for i in range(len(inline)):
                    if 'X 年   X 月  X 日' in inline[i].text:
                        text = inline[i].text.replace('X 年   X 月  X 日', datestr)
                        inline[i].text = text

    doc.save("%s_个人收入证明.docx"%textlist[0])
+ + +

运行后,输入结果:

+

+

+

人生苦短,我用python早下班。如果觉得不错,对你工作中有帮助,请加我微信公众号flypython,我们一起探讨python相关问题

+

flypython微信公众号

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-oa-03/index.html b/article/python-oa-03/index.html new file mode 100644 index 0000000..59bf73d --- /dev/null +++ b/article/python-oa-03/index.html @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python批量转换任意文档格式 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python批量转换任意文档格式

+
+ Author:flypython | Date: 2019-01-03 | Category:自动化办公 +
+
+
+
+
+

在工作中,常常会遇到文档格式的转换。如果数据不多,手工转换就可以。如果是大量文档,那我们应该怎么办呢?

+

今天我们将使用Python来批量处理文档转换的问题.

+

关于unoconv

unoconv是一款跨平台的工具,用于格式转换,支持命令行。底层实现是依赖于开源的LibreOffice/OpenOffice。

+

项目地址:https://github.com/unoconv/unoconv

+

文档地址: http://dag.wiee.rs/home-made/unoconv/

+

根据unoconv的文档介绍,支持上百种文档格式的转换,已经覆盖了绝大部分的需求。

+

使用unoconv

安装unoconv比较繁琐,而且需要针对中文进行进一步的字符集配置。我们可以选择别人已经集成好的服务来进行操作,在这里我们选择了docker-unoconv-webservice项目。

+

项目地址为: https://github.com/zrrrzzt/docker-unoconv-webservice

+

查看项目的README,接口如下:

+

curl --form file=@myfile.docx http://localhost/unoconv/pdf > myfile.pdf

+

我们使用下列命令,先把项目的镜像pull下来

+

docker pull zrrrzzt/docker-unoconv-webservice

+

然后启动命令如下:

+

docker run -d -p 80:3000 zrrrzzt/docker-unoconv-webservice

+

服务在80端口上提供服务,如果80端口被占用,可以调整为其他的端口

+

确认服务正在运行:

+

docker ps | grep zrrrzzt/docker-unoconv-webservice

+
1
2
[flypython] docker ps | grep zrrrzzt/docker-unoconv-webservice                                         
c014cf335b31 zrrrzzt/docker-unoconv-webservice "/bin/sh -c '/usr/bi…" 2 minutes ago Up 2 minutes 0.0.0.0:80->3000/tcp brave_blackburn
+ +

从docx转换为pdf:

+

curl --form file=@demo.docx http://localhost/unoconv/pdf > demo.pdf

+
1
2
3
4
5
6
[flypython] curl --form file=@demo.docx http://localhost/unoconv/pdf > demo.pdf               
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12089 100 4242 100 7847 2532 4684 0:00:01 0:00:01 --:--:-- 7213
[flypython] ls demo*
demo.docx demo.pdf
+ +

使用Python批量请求

Python批量请求的思路是,把需要转换的文档发送到服务器,服务器会返回转换后的格式,我们保存为文件就可以了。

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def post_file(url,path):
filename = os.path.basename(path)
convert_name = str(filename).split('.')[0] + '.pdf'

m = MultipartEncoder(
fields= {
'file':(filename,open(path,'rb')),
}
)
response = requests.request('POST', url, data=m, headers={'Content-Type':m.content_type})

with open(convert_name, 'wb') as f:
f.write(response.content)

return convert_name
+ +

好了,更多类型转换,更完整的应用需要你根据业务来完善,这次的介绍就到这里了。demo完整代码在github上,点击原文可以获取。

+

https://github.com/flypythoncom/flypython/blob/master/convert.py

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-oa-04/index.html b/article/python-oa-04/index.html new file mode 100644 index 0000000..5531825 --- /dev/null +++ b/article/python-oa-04/index.html @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python读取PDF文字和表格 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python读取PDF文字和表格

+
+ Author:flypython | Date: 2019-01-04 | Category:自动化办公 +
+
+
+
+
+
+

【极简Python 自动化办公】专栏是介绍如何利用python办公,减少工作负荷。篇幅精炼,内容易懂,无论是否有编程基础,都非常适合。

+
+

在日常的工作中,处理PDF是最平常不过的事情了。今天带来极简Python自动化办公系列之使用Python提取Pdf文字和表格,希望能够在PDF处理上帮到你。

+

这次我们准备了一个pdf测试文件,内容如下:

+

+

pdf中包括了2页,有文字,图片和表格,覆盖了大部分pdf的场景。

+

pdfplumber介绍

Pdfplumber是一个可以处理pdf格式信息的库。它可以查找关于每个文本字符、矩阵、和行的详细信息,也可以对表格进行提取并进行可视化调试。

+

官方repo:
https://github.com/jsvine/pdfplumber

+

安装:
pip install pdfplumber

+

使用入门

1
2
3
4
5
import pdfplumber

with pdfplumber.open("test.pdf") as pdf:
first_page = pdf.pages[0] #取第一页
print(first_page.chars[0])#打印第一页第一个字文字信息
+ +

结果:

+
1
{'fontname': 'CRSMRF+PingFangTC-Semibold', 'adv': Decimal('1.000'), 'upright': 1, 'x0': Decimal('57.000'), 'y0': Decimal('751.840'), 'x1': Decimal('81.000'), 'y1': Decimal('779.776'), 'width': Decimal('24.000'), 'height': Decimal('27.936'), 'size': Decimal('27.936'), 'object_type': 'char', 'page_number': 1, 'text': '关', 'top': Decimal('62.224'), 'bottom': Decimal('90.160'), 'doctop': Decimal('62.224')}
+ +

格式化之后:

+

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"fontname":"CRSMRF+PingFangTC-Semibold",
"adv":"1.000",
"upright":1,
"x0":"57.000",
"y0":"751.840",
"x1":"81.000",
"y1":"779.776",
"width":"24.000",
"height":"27.936",
"size":"27.936",
"object_type":"char",
"page_number":1, #页数
"text":"关", #第一个文字
"top":"62.224",
"bottom":"90.160",
"doctop":"62.224"
}
+ +

常用方法

    +
  • extract_text() 用来提页面中的文本,将页面的所有字符对象整理为一个字符串
  • +
  • extract_words() 返回的是所有的单词及其相关信息
  • +
  • extract_tables() 提取页面的表格
  • +
+

提取文字

1
2
3
4
5
6
7
8
#!/usr/bin/env python3

import pdfplumber

with pdfplumber.open("test.pdf") as pdf:
first_page = pdf.pages[0]
text = first_page.extract_text() #提取第一页的所有文字
print(text)
+ +

+
1
2
3
4
5
6
7
关于我们
关于FlyPython
FlyPython是提供⼀站式Python编程学习的组织,我们致⼒于为⽤户提供⾼
效,有趣的学习环境,打造专注于Python的中⽂学习社区。
联系我们
客服&合作: 微信号 flypython
微信公众号:
+ +

提取表格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python3

import pdfplumber
import pandas as pd

with pdfplumber.open("test.pdf") as pdf:
first_page = pdf.pages[0]
text = first_page.extract_text()
print(text)

second_page = pdf.pages[1] #第二页
table = second_page.extract_tables()#在第二页提取表格
for t in table:
df = pd.DataFrame(t[1:],columns=t[0])
print(df)
+ +

+
1
2
3
4
5
         分类                 书名
0 Python入门 Python编程:从入门到\n实践
1 Python中级 流畅的Python
2
3
+ +

总结

pdfplumber的接口还是很容易的,如果只是需要提取文字,几行代码就可以提取到。如果是表格并没有提取出来或者错误的提取了非表格的内容,你需要在提取表格时加入table_settings参数来指定表格的设置。

+

这次的demo中,图片并没有提取出来,pdf图片的提取会放到下一篇文章,敬请期待。

+

人生苦短,我用python早下班。如果觉得不错,对你工作中有帮助,可以长按下列二维码关注我们的公众号。

+

flypython微信公众号

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-oa-05/index.html b/article/python-oa-05/index.html new file mode 100644 index 0000000..bfc7dd2 --- /dev/null +++ b/article/python-oa-05/index.html @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python读取PDF图片 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python读取PDF图片

+
+ Author:flypython | Date: 2019-01-05 | Category:自动化办公 +
+
+
+
+
+
+

【极简Python 自动化办公】专栏是介绍如何利用python办公,减少工作负荷。篇幅精炼,内容易懂,无论是否有编程基础,都非常适合。

+
+

在上次的文章中,我们从PDF中提取了文字和表格,这次我们需要提取图片。

+

还是先来看看我们上次的测试例子

+

+

这次我们要提取第一页的二维码图片。

+

fitz介绍

pymupdf是mupdf的Python绑定,而今天我们要使用的fitz是pymupdf的子模块。需要的时候,使用pip安装。

+

pip install pymupdf

+

导入的时使用import fitz导入模块。

+

更多信息可参考pymupdf的文档:
https://pymupdf.readthedocs.io/en/latest/intro/

+

提取图片

提取图片的思路是通过正则表达式找到图片对象,然后保存为图片格式。

+
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
#!/usr/bin/env python3

import fitz #pip install pymupdf
import re
import os

def find_imag(path,img_path):

checkXO = r"/Type(?= */XObject)"
checkIM = r"/Subtype(?= */Image)"

pdf = fitz.open(path)

img_count = 0
len_XREF = pdf._getXrefLength()

print("文件名:{}, 页数: {}, 对象: {}".format(path, len(pdf), len_XREF - 1))

for i in range(1, len_XREF):
text = pdf._getXrefString(i)
isXObject = re.search(checkXO, text)

# 使用正则表达式查看是否是图片
isImage = re.search(checkIM, text)

# 如果不是对象也不是图片,则continue
if not isXObject or not isImage:
continue
img_count += 1
# 根据索引生成图像
pix = fitz.Pixmap(pdf, i)

new_name = path.replace('\\', '_') + "_img{}.png".format(img_count)
new_name = new_name.replace(':', '')

# 如果pix.n<5,可以直接存为PNG
if pix.n < 5:
pix.writePNG(os.path.join(img_path, new_name))

else:
pix0 = fitz.Pixmap(fitz.csRGB, pix)
pix0.writePNG(os.path.join(img_path, new_name))
pix0 = None

pix = None

print("提取了{}张图片".format(img_count))


if __name__=='__main__':
pdf_path = r'test.pdf'
img_path = r'img'
m = find_imag(pdf_path, img_path)
+ +

运行程序结果:

+
1
2
3
[pdf] python3 pdf_img.py
文件名:test.pdf, 页数: 2, 对象: 115
提取了1张图片
+ +

在img目录中,已经存在了我们需要的文件

+

+

总结

pymupdf的使用,今天就简单介绍到这里。更多的功能请参考pymupdf文档。

+

下一篇,我们将带来pdf转换为图片的讨论。

+

人生苦短,我用python早下班。如果觉得不错,对你工作中有帮助,可以长按下列二维码关注我们的公众号。

+

flypython微信公众号

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-tutorial-01/index.html b/article/python-tutorial-01/index.html new file mode 100644 index 0000000..d522397 --- /dev/null +++ b/article/python-tutorial-01/index.html @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 你是如何自学Python的? | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

你是如何自学Python的?

+
+ Author:flypython | Date: 2019-02-01 | Category:Python入门 +
+
+
+
+
+

你是如何自学 Python 的?

+

why python?

+
+

你可能听说过python

+

Python入门相对容易又可以干很多事(网站,>运维,数据,爬虫等),是一门方便的工具语言。
2019年8月TIOBE排名显示Python已经名列第3,仅次于java和c,并且还在快速增长中。

+
+

Python的使用场景

01 数据分析

对于数据分析和机器学习,Python是首选编程语言。python有众多数据分析工具,知名数据分析比赛网站kaggle,90%以上的竞赛代码都是用python写成。大数据平台如spark、flink,python有完整的支持api可调用。

+

02 网站开发

对于网站开发,Python的生态环境也可以支撑起重量级的产品。
国外的Youtube,Instagram,Pinterest,Reddit,Dropbox,Disqus, Quora等知名应用一开始都是基于Python构建,国内的豆瓣,知乎,果壳,饿了么,等初期在也是Python应用的典型。

+

03 爬虫

对于爬虫,则想不到比python更方便、更通用的的语言了。Python极其丰富的生态,诸如Request、Beautiful Soup、Scrapy、PySpider等第三方库,加上简洁易上手的语法,分分钟就能让你写出一个爬虫来。

+

此外,还有机器学习、人工智能、科学计算、IT运维等领域,Python都是极其方便顺手的工具,更重要的是,永远开源,免费。

+

Python的就业前景

在it行业飞速发展的今天,在数据成为it命脉的时代,python的重要意义越来越不言自明。学习python,不仅仅是一门可以调用数据结构和算法的语言,在学会python的同时,可以同时学会爬取互联网海量资源,学会自动化分析互联网海量数据,学会制作展示宣传的网站,学会使用人工智能预测和改变世界。

+

学习一门语言,得到多种技能,以及大数据的思维方式,何乐而不为呢。

+

Python有多火?

Python有多火?大多数IT研发岗位,都需要Python程序员;甚至许多非研发岗位,纷纷在JD中给出精通Python技能者优先的字样。

+

+

+

Python的学习曲线

对于爱好者来说, python上手非常容易,学习曲线非常平滑。基本的例子,几行代码都能完成。

+

python代码环境安装几乎是傻瓜式的,不像java要考虑众多库的配置和解决冲突。如果有编程的基础甚至只需要几小时就能上手,即使没有基础的小白,通过努力,7-10天,每天1小时,也可以快速掌握基本编程技巧。

+

Python的学习资料

Python官网
Python.org

+

廖雪峰的Python教程
https://www.liaoxuefeng.com/

+

简明python教程
http://www.kuqin.com/abyteofpython_cn/

+
+

重点推荐书籍:《Python 基础教程》

+

+

知乎评价:

+

其他入门书籍:

+
    +
  • Head First Python
  • +
  • Dive Into Python
  • +
  • Python 核心编程
  • +
  • 深入理解 Python
  • +
  • Python 标准库
  • +
  • Python 编程指南
  • +
+

(我们搜集了一些网上的电子书版本,关注公众号,回复”python”获取)

+

当然,英文著作虽然经典,但涉及领域众多,概念多,信息量大,不适合速成。网上的资料丰富,但也鱼龙混杂。

+

以 “Python入门” 为关键字搜索出的结果成千上万。不少小白选手难免会东一榔头西一棒槌,最终看了很多文章,却仍没跨过新手那道门槛。

+

我们这里有一个python的入门课程,帮你把需要掌握的python基础知识都融汇贯通在小篇幅中。我们提供了很多有趣的实践项目,并且可以进群,互助学习,遇到困难有人来解答。

+

加群请关注公众号,并回复“训练营”
flypython微信公众号

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-tutorial-02/index.html b/article/python-tutorial-02/index.html new file mode 100644 index 0000000..0e1be01 --- /dev/null +++ b/article/python-tutorial-02/index.html @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 潘石屹:我们为什么要学习Python语言? | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

潘石屹:我们为什么要学习Python语言?

+
+ Author:flypython | Date: 2019-02-02 | Category:Python入门 +
+
+
+
+
+
+

11 月 15 日,SOHO 中国董事长潘石屹在微博上宣布,开始学习一门新的语言 Python,这也是今天给自己人生的礼物。

+
+

+

什么鬼?房地产大佬要学python?

+

+

潘石屹,一位成功的房地产开发商老板,第一专业是石油方面的,63年出生,年龄都超过了55岁,这些描述怎么着都和编程沾不上边啊。然而,最近他非常高调地表示,要学习一款编程语言。
虽然我不同意他的有些观点,不过他的跨界,不给自己设限的态度是还是值得学习的。
大佬都忙着学编程,这让我们35岁左右的专业程序员们非常惭愧啊(难道非得财务自由以后才能学python么)。

+

+

潘石屹学python肯定不是为了转行找工作,肯定也不是为了爬取全网美女图片,他在微博里详细阐述了我们为什么要学习Python语言。

+

+

我们为什么要学习python——使用范围广
01.数据分析

+

对于数据科学和机器学习,Python是首选编程语言。python有众多数据分析工具,知名数据分析比赛网站kaggle,90%以上的竞赛代码都是用python写成。大数据平台如hadoop、spark、flink、beam,python有完整的支持api可调用。

+

02.网站开发

+

对于网站开发,Python的生态环境也可以支撑起重量级的产品。国外的Youtube,Instagram,Pinterest,Reddit,Dropbox,Disqus, Quora等知名应用一开始都是基于Python构建,国内的豆瓣,知乎,果壳,饿了么,等初期在也是Python应用的典型。

+

03.爬虫

+

对于爬虫,则想不到比python更方便、更通用的的语言了。Python极其丰富的生态,诸如Request、Beautiful Soup、Scrapy、PySpider等第三方库,加上简洁易上手的语法,分分钟就能让你写出一个爬虫来。

+

此外,还有机器学习、人工智能、科学计算、IT运维等领域,Python都是极其方便顺手的工具,更重要的是,永远开源,免费。

+

Python的就业前景
在it行业飞速发展的今天,在数据成为it命脉的时代,python的重要意义越来越不言自明。学习python,不仅仅是一门可以调用数据结构和算法的语言,在学会python的同时,可以同时学会爬取互联网海量资源,学会自动化分析互联网海量数据,学会制作展示宣传的网站,学会使用人工智能预测和改变世界。学习一门语言,得到多种技能,以及大数据的思维方式,何乐而不为呢。

+

Python有多火?大多数IT研发岗位,都需要Python程序员;甚至许多非研发岗位,纷纷在JD中给出精通Python技能者优先的字样。

+

Python的学习曲线
对于爱好者来说, python上手非常容易,学习曲线非常平滑。基本的例子,几行代码都能完成。python代码环境安装几乎是傻瓜式的,不像java要考虑众多库的配置和解决冲突。如果有编程的基础甚至只需要几小时就能上手,即使没有基础的小白,通过努力,7-10天,每天1小时,也可以快速掌握基本编程技巧。

+

Python的学习资料

+

Python官网

+

Python.org

+

廖雪峰的Python教程

+

https://www.liaoxuefeng.com/

+

简明的python教程

+

http://www.kuqin.com/abyteofpython_cn/

+

重点推荐书籍:

+

《Python 基础教程》

+

知乎评价:

+

其他入门书籍:

+

Head First Python

+

Dive Into Python

+

Python 核心编程

+

深入理解 Python

+

Python 标准库

+

Python 编程指南

+

(我们搜集了一些网上的电子书版本,关注公众号,回复”python”获取)

+

当然,英文著作虽然经典,但涉及领域众多,概念多,信息量大,不适合速成。网上的资料丰富,但也鱼龙混杂。

+

以 “Python入门” 为关键字搜索出的结果成千上万。不少小白选手难免会东一榔头西一棒槌,最终看了很多文章,却仍没跨过新手那道门槛。

+

我们这里有一个python的入门课程,帮你把需要掌握的python基础知识都融汇贯通在小篇幅中。我们提供了很多有趣的实践项目,并且可以进群,互助学习,遇到困难有人来解答。

+

加群请加个人微信号flypython。

+

人生苦短,我用python早下班。如果觉得不错,对你工作中有帮助,动动手指分享给更多人哦。

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/article/python-tutorial-03/index.html b/article/python-tutorial-03/index.html new file mode 100644 index 0000000..d09b064 --- /dev/null +++ b/article/python-tutorial-03/index.html @@ -0,0 +1,249 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Python正则15分钟入门 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+
+
+

Python正则15分钟入门

+
+ Author:flypython | Date: 2019-02-03 | Category:Python入门 +
+
+
+
+
+

flypython群里有同学问我,如何从大量格式不确定的word文档抽取姓名、电话号码、邮箱等信息存入excel表格。通过之前我们的文章,他已经学会读取和写入文档和表格,但就是无法处理格式不确定的文档。这里介绍的正则方法,可以帮助他解决这个问题。

+

目标

15分钟内让你真正明白正则表达式是什么,并且让你可以在自己的python程序里正确使用它。

+

你将学会:

+
    +
  1. 极简python使用正则的方法
  2. +
  3. 如果利用python高效的匹配字符串
  4. +
  5. 如何利用python正则进行文本判断、过滤、信息提取
  6. +
+

0.极简正则入门

假设程序从word或者excel读取了一串字符串,字符串中有一部分是电话号码,现在需要完整提取这个电话号码。

+
1
2
3
4
import re
reg=re.compile("[0-9]+")
a=reg.findall("我的电话是3555487")
print(a)
+ +

输出:

+

+

解释:
"[0-9]+"是正则表达式,意思是匹配0-9的数字,"+"
表示可以匹配1次-多次,reg.findall表示从后面的字符串里找到所有的匹配值。

+

1.字符集

字符集,又叫元字符,就是用一些特殊符号表示特定种类的字符或位置。

+

匹配字符

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
代码说明
.匹配除换行符以外的任意一个字符
\d匹配数字
\w匹配字母或数字或下划线或汉字
\s匹配任意的空白符
^匹配字符串的开始
$匹配字符串的结束
+

举例

+
1
2
3
4
import re
reg=re.compile("我.")
a=reg.findall("我的电话是3555487")
print(a)
+ +

输出:

+

重复匹配

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
代码说明
*重复0次-无数次
+重复1次-无数次
?重复0次-1次
{m}重复m次
{m,n}重复m-n次
+

举例

+
1
2
3
4
import re
reg=re.compile("5+")
a=reg.findall("我的电话是3555487")
print(a)
+ +

输出:

+

贪婪与懒惰

贪婪:匹配尽可能长的字符串
懒惰:匹配尽可能短的字符串
懒惰模式的启用只需在重复元字符之后加?既可。

+
    +
  • *? 重复任意次,但尽可能少重复
  • +
  • +? 重复1次或更多次,但尽可能少重复
  • +
  • ?? 重复0次或1次,但尽可能少重复
  • +
  • {n,m}? 重复n到m次,但尽可能少重复
  • +
  • {n,}? 重复n次以上,但尽可能少重复
  • +
+

举例

+
1
2
3
4
import re
reg=re.compile("5+?")
a=reg.findall("我的电话是3555487")
print(a)
+ +

输出

+

注意:
如果想匹配元字符本身或者正则中的一些特殊字符,使用\\转义。

+

这里介绍的正则内容是最基础的,想要了解更详细的正则表达式语法,请参考:

+

2.利用正则判断

判断

有时候我们想利用正则表达式对用户输入进行判断,比如判断用户输入的身份证号是否符合规则,那么可以这样写:

+
1
2
3
4
5
6
7
8
9
10
11
import re
r=r'^([1-9]\d{5}[12]\d{3}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])\d{3}[0-9xX])$'

s1 = '110102200101014779'

#判断s1字符串是符合正则r
an = re.search(r, s1)
if an:
print ('yes')
else:
print ('no')
+ +

输入结果

+

说明:^字符表示必须匹配字符串开头;$表示必须匹配字符串结尾。

+

过滤

假设,输出一串文本,只想保留汉字,去除特殊符号。代码如下:

+
1
2
3
4
5
import re
special_character_removal = re.compile(r'[,。、【 】“”:;()《》‘’{}?!⑦%>℃.^-——=&#@¥『』]', re.IGNORECASE)
line="贾蓉看了说:“高明的很。还要请教先生,这病与『性』命终久有妨无妨?”"
l = special_character_removal.sub('', line)
print(l)
+ +

输入结果:

+

查找位置

查找某个文本在字符串中的位置,一般用于信息提取。

+
1
2
3
4
5
6
7
8
import re
p = re.compile("\d+")
content="2019年9月9月9日"
result2 = p.finditer(content)

for m in result2:
print("str",m.group()) ##字符串
print("start: ",m.start()," end: ",m.end()) ##字符串位置
+ +

输出结果

+

+

人生苦短,我用python早下班。如果觉得不错,对你工作中有帮助,请长按下面二维码关注我们。(回复训练营加群,一起探讨python问题)

+

flypython微信公众号

+ +
+
+
+ +
+ + + + +
+ +
+ + + + + + + + + diff --git a/css/f25.css b/css/f25.css new file mode 100644 index 0000000..d9c919b --- /dev/null +++ b/css/f25.css @@ -0,0 +1,503 @@ +body{ + margin: 0; + font-family: "PingFang SC","Lantinghei SC","Microsoft Yahei","Hiragino Sans GB","Microsoft Sans Serif","WenQuanYi Micro Hei",sans; + -webkit-font-smoothing: antialiased; + -webkit-text-size-adjust: 100%; + -ms-text-size-adjust: 100%; + text-rendering: optimizelegibility; + -webkit-overflow-scrolling: touch; + overflow: scroll; +} +html , body{ + height: 100%; +} +.header-wrapper{ + height: 64px; + width: 100%; + position: fixed; + top: 0; + left: 0; + z-index: 999; + background: #fff; + box-shadow: 0px 1px 2px #999; +} +.wrapper{ + width: 100%; +} +.wrapper::before, +.wrapper::after{ + clear: both; + display: table; + content: ""; +} +.container{ + width: 1200px; + margin: 0 auto; +} +.sub-container{ + width: 960px; + margin: 0 auto; +} +.container::before, +.container::after, +.sub-container::before, +.sub-container::after{ + clear: both; + display: table; + content: ""; +} +.header-nav-wrapper{ + height: 100%; + position: relative; +} + +.logo{ + float: left; + height: 100%; + width: 200px; + background: #fff; +} +.logo a{ + width: 100%; + height: 100%; + color: #03339e; + text-decoration: none; +} +.logo a:hover, +.logo a:visited, +.logo a:acive{ + color: #03339e; + text-decoration: none; +} +.logo .title{ + margin: 0; + padding: 0; + line-height: 64px; + user-select: none; + width: 100%; + height: 100%; + font-size: 24px; + box-sizing: border-box; +} +.nav-wrapper{ + float: right; +} +.nav-wrapper a{ + display: block; + float: left; + height: 100%; + font-size: 18px; + line-height: 20px; + padding: 22px; + color: #000; + cursor: pointer; + text-decoration: none; + transition: all .4s; +} +.nav-wrapper a:hover{ + color: #fff; + background-color: #6C62C7; + text-decoration: none; +} +.nav-wrapper a:active, +.nav-wrapper a:visited{ + text-decoration: none; +} +.body-wrapper{ + min-height: 100%; + box-sizing: border-box; + padding: 64px 0 60px 0; + position: relative; +} +.banner-wrapper{ + height: 250px; + background: url(/images/bg_sm.png) repeat; + background-color: #000; +} +.banner-container{ + height: 100%; + background: url(/images/bg.png) no-repeat; + background-position: center; + background-size: auto 100%; +} +.menu-wrapper{ + margin-top: 20px; +} +.menu-wrapper a{ + text-decoration: none; + color: #333; + font-size: 16px; + box-sizing: border-box; + font-weight: 600; + padding: 10px 20px; + float: left; + transition: all .4s; + margin-right: 10px; + +} +.menu-wrapper a:lash-child{ + margin-right: 0; +} +.menu-wrapper a.active, +.menu-wrapper a:hover{ + text-decoration: none; + color: #fff; + background-color: #6C62C7; +} +.list-container{ + padding: 0; +} +.post-i-wrapper{ + list-style: none; + width: 280px; + height: 240px; + float: left; + margin: 26px 26px 26px 0; + background-color: #fff; + cursor: pointer; + box-shadow: 0px 2px 6px #ccc; + transition: all .2s; +} +.post-i-wrapper .post-i-link{ + width: 100%; + height: 100%; + text-decoration: none; +} +.post-i-wrapper:hover{ + box-shadow: 0px 0px 10px #000; +} +.post-i-wrapper .cover{ + width: 100%; + height: 113px; + overflow: hidden; +} +.post-i-wrapper .cover img{ + width: 100%; + min-height: 100%; +} +.post-i-wrapper .title{ + margin: 0; + font-size: 18px; + font-weight: 400; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + box-sizing: border-box; + padding: 20px 10px 10px 10px; + color: #000; +} +.post-i-wrapper .subtitle{ + line-height: 22px; + text-indent: 28px; + font-size: 14px; + font-weight: 400; + max-height: 44px; + overflow: hidden; + box-sizing: border-box; + padding: 0 10px; + color: #666; + margin: 0; +} +.post-i-wrapper .time{ + color: #999; + font-size: 12px; + padding: 10px; + display: block; + box-sizing: border-box; + text-align: left; +} +.post-banner{ + height: 400px; + background-color: #6C62C7; +} +.post-banner-container{ + height: 100%; + background: url(/images/bg_post.png) no-repeat; + background-position: center; + background-size: 100% auto; +} +.post-banner-container .title{ + width: 100%; + text-align: center; + font-size: 28px; + line-height: 40px; + margin: 0; + margin-top: 160px; + font-weight: 500; + color: #fff; +} +.post-banner-container .tips { + text-align: center; + color: #D8D8F6; +} +.post-banner-container .tips a{ + color: #D8D8F6; + text-decoration: none; + transition: all .4s; +} +.post-banner-container .tips a:hover{ + color: #3A2BB4; + text-decoration: underline; +} +.post-content { + box-sizing: border-box; + padding: 20px 10px; + line-height: 1.8; +} +.post-content ul, +.post-content ol{ + box-sizing: border-box; + padding: 20px 10px; + margin: 0; +} +.post-content table{ + border-spacing: 0; + border-collapse: collapse; + -ms-word-break: break-all; + word-break: break-all; +} +.post-content table th{ + background: #eee; + padding: 4px; + border: 1px solid #999; +} +.post-content table td{ + border: 1px solid #999; + padding: 4px; +} +.post-content li{ + font-weight: 500; + line-height: 2; + color: #333; + -ms-word-break: break-all; + word-break: break-all; + list-style-position: inside; +} +.post-content p{ + -ms-word-break: break-all; + word-break: break-all; +} +.gitalk-wrapper{ + padding: 20px 10px; + box-sizing: border-box; +} +.footer-wrapper{ + width: 100%; + position: absolute; + bottom: 0; + left: 0; + height: 60px; + text-align: center; + background: #efefef; + box-sizing: border-box; + padding: 20px 0; + box-shadow: 0px 0px 2px #bbb; +} +.copyright{ + font-size: 14px; + vertical-align: middle; +} +.btn-menu { + display: none; + float: right; + width: 64px; + height: 64px; +} +.btn-menu .inner { + width: 100%; + height: 100%; + overflow: hidden; + position: relative; +} +.btn-menu .inner .line { + top: 30px; + left: 22px; + position: absolute; + width: 20px; + height: 3px; + -webkit-transition: all .5s; + transition: all .5s; + background: #000; +} +.btn-menu .inner .line-01 { + margin-top: -7px; +} +.btn-menu .inner .line-03 { + margin-top: 7px; +} +.btn-close .line-01 { + -webkit-transform: rotate(45deg) translate3d(5px, 5px, 0); + transform: rotate(45deg) translate3d(5px, 5px, 0); +} +.btn-close .line-03 { + -webkit-transform: rotate(-45deg) translate3d(5px, -5px, 0); + transform: rotate(-45deg) translate3d(5px, -5px, 0); +} +.btn-close .line-02 { + -webkit-transform: translate3d(50px, 0, 0); + transform: translate3d(50px, 0, 0); +} +.mb-nav-wrapper{ + position: absolute; + top: 64px; + z-index: 99; + background-color: #fff; + box-shadow: 0px 1px 2px #999; + display: none; +} +.mb-nav-wrapper.show{ + display: block; +} +.mb-nav-container a{ + display: block; + box-sizing: border-box; + padding: 10px; + line-height: 22px; + font-size: 14px; + text-decoration: none; + color: #000; + user-select: none; +} +.tips-top-wrapper{ + width: 40px; + height: 40px; + background: #d4d4d4; + margin-bottom: .5rem; + cursor: pointer; + transition: all .4s; + border-radius: 2px; + box-shadow: 2px 2px 2px #000; + position: fixed; + bottom: 20px; + right: 20px; + z-index: 99; +} +.tips-top-wrapper:hover{ + background: #000; + } +.tip-top-container{ + display: block; + width: 100%; + height: 100%; + text-align: center; + line-height: 48px; + position: relative; +} +.tip-top-container span{ + width: 2px; + height: 16px; + background: #fff; + display: block; + position: absolute; +} +.tip-top-container .l-bar{ + transform: rotateZ(45deg); + -ms-transform: rotateZ(45deg); + -webkit-transform: rotateZ(45deg); + left: 14px; + top: 12px; +} +.tip-top-container .r-bar{ + transform: rotateZ(-45deg); + -ms-transform: rotateZ(-45deg); + -webkit-transform: rotateZ(-45deg); + left: 25px; + top: 12px; +} +/****************************/ + +@media screen and (min-width: 901px) and (max-width: 1400px){ + .container, + .sub-container{ + width: 892px; + } + .post-i-wrapper{ + margin: 26px 26px 26px 0; + } + .post-i-wrapper:nth-child(3n){ + margin-right: 0; + } +} +@media screen and (min-width: 769px) and (max-width: 900px){ + .container, + .sub-container{ + width: 586px; + } + .post-i-wrapper{ + margin: 26px 26px 26px 0; + } + .post-i-wrapper:nth-child(2n){ + margin-right: 0; + } + .nav-wrapper a{ + padding: 22px 12px; + } + .menu-wrapper a{ + padding: 10px 8px; + } + .post-banner-container .title{ + font-size: 24px; + } +} +@media screen and (max-width: 768px){ + .container, + .sub-container{ + width: 100%; + } + .list-container{ + box-sizing: border-box; + padding: 10px 2px; + } + .post-i-wrapper{ + height: 320px; + width: 100%; + margin: 26px 0; + } + .post-i-wrapper .cover{ + height: 193px; + } + .logo .title{ + padding: 0 10px; + } + .nav-wrapper{ + display: none; + } + .logo{ + width: 140px; + } + .btn-menu{ + display: block; + } + .post-banner{ + height: 200px; + } + .post-banner-container .title{ + margin-top: 80px; + font-size: 18px; + line-height: 24px; + } + .post-banner-container .tips{ + font-size: 12px; + } + .post-content{ + font-size: 14px; + } + .menu-wrapper{ + box-sizing: border-box; + padding: 0 10px; + } + .menu-wrapper a{ + padding: 8px; + font-size: 14px; + } +} + +@media screen and ( min-width:1401px){ + .post-i-wrapper{ + margin: 26px 26px 26px 0; + } + .post-i-wrapper:nth-child(4n){ + margin-right: 0; + } +} + diff --git a/css/gitalk.css b/css/gitalk.css new file mode 100644 index 0000000..87acb21 --- /dev/null +++ b/css/gitalk.css @@ -0,0 +1,1211 @@ +@font-face { + font-family: octicons-link; + src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAZwABAAAAAACFQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEU0lHAAAGaAAAAAgAAAAIAAAAAUdTVUIAAAZcAAAACgAAAAoAAQAAT1MvMgAAAyQAAABJAAAAYFYEU3RjbWFwAAADcAAAAEUAAACAAJThvmN2dCAAAATkAAAABAAAAAQAAAAAZnBnbQAAA7gAAACyAAABCUM+8IhnYXNwAAAGTAAAABAAAAAQABoAI2dseWYAAAFsAAABPAAAAZwcEq9taGVhZAAAAsgAAAA0AAAANgh4a91oaGVhAAADCAAAABoAAAAkCA8DRGhtdHgAAAL8AAAADAAAAAwGAACfbG9jYQAAAsAAAAAIAAAACABiATBtYXhwAAACqAAAABgAAAAgAA8ASm5hbWUAAAToAAABQgAAAlXu73sOcG9zdAAABiwAAAAeAAAAME3QpOBwcmVwAAAEbAAAAHYAAAB/aFGpk3jaTY6xa8JAGMW/O62BDi0tJLYQincXEypYIiGJjSgHniQ6umTsUEyLm5BV6NDBP8Tpts6F0v+k/0an2i+itHDw3v2+9+DBKTzsJNnWJNTgHEy4BgG3EMI9DCEDOGEXzDADU5hBKMIgNPZqoD3SilVaXZCER3/I7AtxEJLtzzuZfI+VVkprxTlXShWKb3TBecG11rwoNlmmn1P2WYcJczl32etSpKnziC7lQyWe1smVPy/Lt7Kc+0vWY/gAgIIEqAN9we0pwKXreiMasxvabDQMM4riO+qxM2ogwDGOZTXxwxDiycQIcoYFBLj5K3EIaSctAq2kTYiw+ymhce7vwM9jSqO8JyVd5RH9gyTt2+J/yUmYlIR0s04n6+7Vm1ozezUeLEaUjhaDSuXHwVRgvLJn1tQ7xiuVv/ocTRF42mNgZGBgYGbwZOBiAAFGJBIMAAizAFoAAABiAGIAznjaY2BkYGAA4in8zwXi+W2+MjCzMIDApSwvXzC97Z4Ig8N/BxYGZgcgl52BCSQKAA3jCV8CAABfAAAAAAQAAEB42mNgZGBg4f3vACQZQABIMjKgAmYAKEgBXgAAeNpjYGY6wTiBgZWBg2kmUxoDA4MPhGZMYzBi1AHygVLYQUCaawqDA4PChxhmh/8ODDEsvAwHgMKMIDnGL0x7gJQCAwMAJd4MFwAAAHjaY2BgYGaA4DAGRgYQkAHyGMF8NgYrIM3JIAGVYYDT+AEjAwuDFpBmA9KMDEwMCh9i/v8H8sH0/4dQc1iAmAkALaUKLgAAAHjaTY9LDsIgEIbtgqHUPpDi3gPoBVyRTmTddOmqTXThEXqrob2gQ1FjwpDvfwCBdmdXC5AVKFu3e5MfNFJ29KTQT48Ob9/lqYwOGZxeUelN2U2R6+cArgtCJpauW7UQBqnFkUsjAY/kOU1cP+DAgvxwn1chZDwUbd6CFimGXwzwF6tPbFIcjEl+vvmM/byA48e6tWrKArm4ZJlCbdsrxksL1AwWn/yBSJKpYbq8AXaaTb8AAHja28jAwOC00ZrBeQNDQOWO//sdBBgYGRiYWYAEELEwMTE4uzo5Zzo5b2BxdnFOcALxNjA6b2ByTswC8jYwg0VlNuoCTWAMqNzMzsoK1rEhNqByEyerg5PMJlYuVueETKcd/89uBpnpvIEVomeHLoMsAAe1Id4AAAAAAAB42oWQT07CQBTGv0JBhagk7HQzKxca2sJCE1hDt4QF+9JOS0nbaaYDCQfwCJ7Au3AHj+LO13FMmm6cl7785vven0kBjHCBhfpYuNa5Ph1c0e2Xu3jEvWG7UdPDLZ4N92nOm+EBXuAbHmIMSRMs+4aUEd4Nd3CHD8NdvOLTsA2GL8M9PODbcL+hD7C1xoaHeLJSEao0FEW14ckxC+TU8TxvsY6X0eLPmRhry2WVioLpkrbp84LLQPGI7c6sOiUzpWIWS5GzlSgUzzLBSikOPFTOXqly7rqx0Z1Q5BAIoZBSFihQYQOOBEdkCOgXTOHA07HAGjGWiIjaPZNW13/+lm6S9FT7rLHFJ6fQbkATOG1j2OFMucKJJsxIVfQORl+9Jyda6Sl1dUYhSCm1dyClfoeDve4qMYdLEbfqHf3O/AdDumsjAAB42mNgYoAAZQYjBmyAGYQZmdhL8zLdDEydARfoAqIAAAABAAMABwAKABMAB///AA8AAQAAAAAAAAAAAAAAAAABAAAAAA==) format('woff'); + } + + .markdown-body { + -ms-text-size-adjust: 100%; + -webkit-text-size-adjust: 100%; + line-height: 1.5; + color: #24292e; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; + font-size: 16px; + line-height: 1.5; + word-wrap: break-word; + } + + .markdown-body .pl-c { + color: #6a737d; + } + + .markdown-body .pl-c1, + .markdown-body .pl-s .pl-v { + color: #005cc5; + } + + .markdown-body .pl-e, + .markdown-body .pl-en { + color: #6f42c1; + } + + .markdown-body .pl-smi, + .markdown-body .pl-s .pl-s1 { + color: #24292e; + } + + .markdown-body .pl-ent { + color: #22863a; + } + + .markdown-body .pl-k { + color: #d73a49; + } + + .markdown-body .pl-s, + .markdown-body .pl-pds, + .markdown-body .pl-s .pl-pse .pl-s1, + .markdown-body .pl-sr, + .markdown-body .pl-sr .pl-cce, + .markdown-body .pl-sr .pl-sre, + .markdown-body .pl-sr .pl-sra { + color: #032f62; + } + + .markdown-body .pl-v, + .markdown-body .pl-smw { + color: #e36209; + } + + .markdown-body .pl-bu { + color: #b31d28; + } + + .markdown-body .pl-ii { + color: #fafbfc; + background-color: #b31d28; + } + + .markdown-body .pl-c2 { + color: #fafbfc; + background-color: #d73a49; + } + + .markdown-body .pl-c2::before { + content: "^M"; + } + + .markdown-body .pl-sr .pl-cce { + font-weight: bold; + color: #22863a; + } + + .markdown-body .pl-ml { + color: #735c0f; + } + + .markdown-body .pl-mh, + .markdown-body .pl-mh .pl-en, + .markdown-body .pl-ms { + font-weight: bold; + color: #005cc5; + } + + .markdown-body .pl-mi { + font-style: italic; + color: #24292e; + } + + .markdown-body .pl-mb { + font-weight: bold; + color: #24292e; + } + + .markdown-body .pl-md { + color: #b31d28; + background-color: #ffeef0; + } + + .markdown-body .pl-mi1 { + color: #22863a; + background-color: #f0fff4; + } + + .markdown-body .pl-mc { + color: #e36209; + background-color: #ffebda; + } + + .markdown-body .pl-mi2 { + color: #f6f8fa; + background-color: #005cc5; + } + + .markdown-body .pl-mdr { + font-weight: bold; + color: #6f42c1; + } + + .markdown-body .pl-ba { + color: #586069; + } + + .markdown-body .pl-sg { + color: #959da5; + } + + .markdown-body .pl-corl { + text-decoration: underline; + color: #032f62; + } + + .markdown-body .octicon { + display: inline-block; + vertical-align: text-top; + fill: currentColor; + } + + .markdown-body a { + background-color: transparent; + -webkit-text-decoration-skip: objects; + } + + .markdown-body a:active, + .markdown-body a:hover { + outline-width: 0; + } + + .markdown-body strong { + font-weight: inherit; + } + + .markdown-body strong { + font-weight: bolder; + } + + .markdown-body h1 { + font-size: 2em; + margin: 0.67em 0; + } + + .markdown-body img { + border-style: none; + } + + .markdown-body svg:not(:root) { + overflow: hidden; + } + + .markdown-body code, + .markdown-body kbd, + .markdown-body pre { + font-family: monospace, monospace; + font-size: 1em; + } + + .markdown-body hr { + -webkit-box-sizing: content-box; + box-sizing: content-box; + height: 0; + overflow: visible; + } + + .markdown-body input { + font: inherit; + margin: 0; + } + + .markdown-body input { + overflow: visible; + } + + .markdown-body [type="checkbox"] { + -webkit-box-sizing: border-box; + box-sizing: border-box; + padding: 0; + } + + .markdown-body * { + -webkit-box-sizing: border-box; + box-sizing: border-box; + } + + .markdown-body input { + font-family: inherit; + font-size: inherit; + line-height: inherit; + } + + .markdown-body a { + color: #0366d6; + text-decoration: none; + } + + .markdown-body a:hover { + text-decoration: underline; + } + + .markdown-body strong { + font-weight: 600; + } + + .markdown-body hr { + height: 0; + margin: 15px 0; + overflow: hidden; + background: transparent; + border: 0; + border-bottom: 1px solid #dfe2e5; + } + + .markdown-body hr::before { + display: table; + content: ""; + } + + .markdown-body hr::after { + display: table; + clear: both; + content: ""; + } + + .markdown-body table { + border-spacing: 0; + border-collapse: collapse; + } + + .markdown-body td, + .markdown-body th { + padding: 0; + } + + .markdown-body h1, + .markdown-body h2, + .markdown-body h3, + .markdown-body h4, + .markdown-body h5, + .markdown-body h6 { + margin-top: 0; + margin-bottom: 0; + } + + .markdown-body h1 { + font-size: 32px; + font-weight: 600; + } + + .markdown-body h2 { + font-size: 24px; + font-weight: 600; + } + + .markdown-body h3 { + font-size: 20px; + font-weight: 600; + } + + .markdown-body h4 { + font-size: 16px; + font-weight: 600; + } + + .markdown-body h5 { + font-size: 14px; + font-weight: 600; + } + + .markdown-body h6 { + font-size: 12px; + font-weight: 600; + } + + .markdown-body p { + margin-top: 0; + margin-bottom: 10px; + } + + .markdown-body blockquote { + margin: 0; + } + + .markdown-body ul, + .markdown-body ol { + padding-left: 0; + margin-top: 0; + margin-bottom: 0; + } + + .markdown-body ol ol, + .markdown-body ul ol { + list-style-type: lower-roman; + } + + .markdown-body ul ul ol, + .markdown-body ul ol ol, + .markdown-body ol ul ol, + .markdown-body ol ol ol { + list-style-type: lower-alpha; + } + + .markdown-body dd { + margin-left: 0; + } + + .markdown-body code { + font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + font-size: 12px; + } + + .markdown-body pre { + margin-top: 0; + margin-bottom: 0; + font: 12px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + } + + .markdown-body .octicon { + vertical-align: text-bottom; + } + + .markdown-body .pl-0 { + padding-left: 0 !important; + } + + .markdown-body .pl-1 { + padding-left: 4px !important; + } + + .markdown-body .pl-2 { + padding-left: 8px !important; + } + + .markdown-body .pl-3 { + padding-left: 16px !important; + } + + .markdown-body .pl-4 { + padding-left: 24px !important; + } + + .markdown-body .pl-5 { + padding-left: 32px !important; + } + + .markdown-body .pl-6 { + padding-left: 40px !important; + } + + .markdown-body::before { + display: table; + content: ""; + } + + .markdown-body::after { + display: table; + clear: both; + content: ""; + } + + .markdown-body>*:first-child { + margin-top: 0 !important; + } + + .markdown-body>*:last-child { + margin-bottom: 0 !important; + } + + .markdown-body a:not([href]) { + color: inherit; + text-decoration: none; + } + + .markdown-body .anchor { + float: left; + padding-right: 4px; + margin-left: -20px; + line-height: 1; + } + + .markdown-body .anchor:focus { + outline: none; + } + + .markdown-body p, + .markdown-body blockquote, + .markdown-body ul, + .markdown-body ol, + .markdown-body dl, + .markdown-body table, + .markdown-body pre { + margin-top: 0; + margin-bottom: 16px; + } + + .markdown-body hr { + height: 0.25em; + padding: 0; + margin: 24px 0; + background-color: #e1e4e8; + border: 0; + } + + .markdown-body blockquote { + padding: 0 1em; + color: #6a737d; + border-left: 0.25em solid #dfe2e5; + } + + .markdown-body blockquote>:first-child { + margin-top: 0; + } + + .markdown-body blockquote>:last-child { + margin-bottom: 0; + } + + .markdown-body kbd { + display: inline-block; + padding: 3px 5px; + font-size: 11px; + line-height: 10px; + color: #444d56; + vertical-align: middle; + background-color: #fafbfc; + border: solid 1px #c6cbd1; + border-bottom-color: #959da5; + border-radius: 3px; + -webkit-box-shadow: inset 0 -1px 0 #959da5; + box-shadow: inset 0 -1px 0 #959da5; + } + + .markdown-body h1, + .markdown-body h2, + .markdown-body h3, + .markdown-body h4, + .markdown-body h5, + .markdown-body h6 { + margin-top: 24px; + margin-bottom: 16px; + font-weight: 600; + line-height: 1.25; + } + + .markdown-body h1 .octicon-link, + .markdown-body h2 .octicon-link, + .markdown-body h3 .octicon-link, + .markdown-body h4 .octicon-link, + .markdown-body h5 .octicon-link, + .markdown-body h6 .octicon-link { + color: #1b1f23; + vertical-align: middle; + visibility: hidden; + } + + .markdown-body h1:hover .anchor, + .markdown-body h2:hover .anchor, + .markdown-body h3:hover .anchor, + .markdown-body h4:hover .anchor, + .markdown-body h5:hover .anchor, + .markdown-body h6:hover .anchor { + text-decoration: none; + } + + .markdown-body h1:hover .anchor .octicon-link, + .markdown-body h2:hover .anchor .octicon-link, + .markdown-body h3:hover .anchor .octicon-link, + .markdown-body h4:hover .anchor .octicon-link, + .markdown-body h5:hover .anchor .octicon-link, + .markdown-body h6:hover .anchor .octicon-link { + visibility: visible; + } + + .markdown-body h1 { + padding-bottom: 0.3em; + font-size: 2em; + border-bottom: 1px solid #eaecef; + } + + .markdown-body h2 { + padding-bottom: 0.3em; + font-size: 1.5em; + border-bottom: 1px solid #eaecef; + } + + .markdown-body h3 { + font-size: 1.25em; + } + + .markdown-body h4 { + font-size: 1em; + } + + .markdown-body h5 { + font-size: 0.875em; + } + + .markdown-body h6 { + font-size: 0.85em; + color: #6a737d; + } + + .markdown-body ul, + .markdown-body ol { + padding-left: 2em; + } + + .markdown-body ul ul, + .markdown-body ul ol, + .markdown-body ol ol, + .markdown-body ol ul { + margin-top: 0; + margin-bottom: 0; + } + + .markdown-body li>p { + margin-top: 16px; + } + + .markdown-body li+li { + margin-top: 0.25em; + } + + .markdown-body dl { + padding: 0; + } + + .markdown-body dl dt { + padding: 0; + margin-top: 16px; + font-size: 1em; + font-style: italic; + font-weight: 600; + } + + .markdown-body dl dd { + padding: 0 16px; + margin-bottom: 16px; + } + + .markdown-body table { + display: block; + width: 100%; + overflow: auto; + } + + .markdown-body table th { + font-weight: 600; + } + + .markdown-body table th, + .markdown-body table td { + padding: 6px 13px; + border: 1px solid #dfe2e5; + } + + .markdown-body table tr { + background-color: #fff; + border-top: 1px solid #c6cbd1; + } + + .markdown-body table tr:nth-child(2n) { + background-color: #f6f8fa; + } + + .markdown-body img { + max-width: 100%; + -webkit-box-sizing: content-box; + box-sizing: content-box; + background-color: #fff; + } + + .markdown-body code { + padding: 0; + padding-top: 0.2em; + padding-bottom: 0.2em; + margin: 0; + font-size: 85%; + background-color: rgba(27,31,35,0.05); + border-radius: 3px; + } + + .markdown-body code::before, + .markdown-body code::after { + letter-spacing: -0.2em; + content: "\A0"; + } + + .markdown-body pre { + word-wrap: normal; + } + + .markdown-body pre>code { + padding: 0; + margin: 0; + font-size: 100%; + word-break: normal; + white-space: pre; + background: transparent; + border: 0; + } + + .markdown-body .highlight { + margin-bottom: 16px; + } + + .markdown-body .highlight pre { + margin-bottom: 0; + word-break: normal; + } + + .markdown-body .highlight pre, + .markdown-body pre { + padding: 16px; + overflow: auto; + font-size: 85%; + line-height: 1.45; + background-color: #f6f8fa; + border-radius: 3px; + } + + .markdown-body pre code { + display: inline; + max-width: auto; + padding: 0; + margin: 0; + overflow: visible; + line-height: inherit; + word-wrap: normal; + background-color: transparent; + border: 0; + } + + .markdown-body pre code::before, + .markdown-body pre code::after { + content: normal; + } + + .markdown-body .full-commit .btn-outline:not(:disabled):hover { + color: #005cc5; + border-color: #005cc5; + } + + .markdown-body kbd { + display: inline-block; + padding: 3px 5px; + font: 11px "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; + line-height: 10px; + color: #444d56; + vertical-align: middle; + background-color: #fafbfc; + border: solid 1px #d1d5da; + border-bottom-color: #c6cbd1; + border-radius: 3px; + -webkit-box-shadow: inset 0 -1px 0 #c6cbd1; + box-shadow: inset 0 -1px 0 #c6cbd1; + } + + .markdown-body :checked+.radio-label { + position: relative; + z-index: 1; + border-color: #0366d6; + } + + .markdown-body .task-list-item { + list-style-type: none; + } + + .markdown-body .task-list-item+.task-list-item { + margin-top: 3px; + } + + .markdown-body .task-list-item input { + margin: 0 0.2em 0.25em -1.6em; + vertical-align: middle; + } + + .markdown-body hr { + border-bottom-color: #eee; + } + /* variables */ + /* functions & mixins */ + /* variables - calculated */ + /* styles */ + .gt-container { + -webkit-box-sizing: border-box; + box-sizing: border-box; + font-size: 16px; + /* loader */ + /* error */ + /* initing */ + /* no int */ + /* link */ + /* meta */ + /* popup */ + /* header */ + /* comments */ + /* comment */ + } + .gt-container * { + -webkit-box-sizing: border-box; + box-sizing: border-box; + } + .gt-container a { + color: #6190e8; + } + .gt-container a:hover { + color: #81a6ed; + border-color: #81a6ed; + } + .gt-container a.is--active { + color: #333; + cursor: default !important; + } + .gt-container a.is--active:hover { + color: #333; + } + .gt-container .hide { + display: none !important; + } + .gt-container .gt-svg { + display: inline-block; + width: 1em; + height: 1em; + vertical-align: sub; + } + .gt-container .gt-svg svg { + width: 100%; + height: 100%; + fill: #6190e8; + } + .gt-container .gt-ico { + display: inline-block; + } + .gt-container .gt-ico-text { + margin-left: 0.3125em; + } + .gt-container .gt-ico-github { + width: 100%; + height: 100%; + } + .gt-container .gt-ico-github .gt-svg { + width: 100%; + height: 100%; + } + .gt-container .gt-ico-github svg { + fill: inherit; + } + .gt-container .gt-spinner { + position: relative; + } + .gt-container .gt-spinner::before { + content: ''; + -webkit-box-sizing: border-box; + box-sizing: border-box; + position: absolute; + top: 3px; + width: 0.75em; + height: 0.75em; + margin-top: -0.1875em; + margin-left: -0.375em; + border-radius: 50%; + border: 1px solid #fff; + border-top-color: #6190e8; + -webkit-animation: gt-kf-rotate 0.6s linear infinite; + animation: gt-kf-rotate 0.6s linear infinite; + } + .gt-container .gt-loader { + position: relative; + border: 1px solid #999; + -webkit-animation: ease gt-kf-rotate 1.5s infinite; + animation: ease gt-kf-rotate 1.5s infinite; + display: inline-block; + font-style: normal; + width: 1.75em; + height: 1.75em; + line-height: 1.75em; + border-radius: 50%; + } + .gt-container .gt-loader:before { + content: ''; + position: absolute; + display: block; + top: 0; + left: 50%; + margin-top: -0.1875em; + margin-left: -0.1875em; + width: 0.375em; + height: 0.375em; + background-color: #999; + border-radius: 50%; + } + .gt-container .gt-avatar { + display: inline-block; + width: 3.125em; + height: 3.125em; + } + @media (max-width: 479px) { + .gt-container .gt-avatar { + width: 2em; + height: 2em; + } + } + .gt-container .gt-avatar img { + width: 100%; + height: auto; + border-radius: 3px; + } + .gt-container .gt-avatar-github { + width: 3em; + height: 3em; + } + @media (max-width: 479px) { + .gt-container .gt-avatar-github { + width: 1.875em; + height: 1.875em; + } + } + .gt-container .gt-btn { + padding: 0.75em 1.25em; + display: inline-block; + line-height: 1; + text-decoration: none; + white-space: nowrap; + cursor: pointer; + border: 1px solid #6190e8; + border-radius: 5px; + background-color: #6190e8; + color: #fff; + outline: none; + font-size: 0.75em; + } + .gt-container .gt-btn-text { + font-weight: 400; + } + .gt-container .gt-btn-loading { + position: relative; + margin-left: 0.5em; + display: inline-block; + width: 0.75em; + height: 1em; + vertical-align: top; + } + .gt-container .gt-btn.is--disable { + cursor: not-allowed; + opacity: 0.5; + } + .gt-container .gt-btn-login { + margin-right: 0; + } + .gt-container .gt-btn-preview { + background-color: #fff; + color: #6190e8; + } + .gt-container .gt-btn-preview:hover { + background-color: #f2f2f2; + border-color: #81a6ed; + } + .gt-container .gt-btn-public:hover { + background-color: #81a6ed; + border-color: #81a6ed; + } + .gt-container .gt-error { + text-align: center; + margin: 0.625em; + color: #ff3860; + } + .gt-container .gt-initing { + padding: 1.25em 0; + text-align: center; + } + .gt-container .gt-initing-text { + margin: 0.625em auto; + font-size: 92%; + } + .gt-container .gt-no-init { + padding: 1.25em 0; + text-align: center; + } + .gt-container .gt-link { + border-bottom: 1px dotted #6190e8; + } + .gt-container .gt-link-counts, + .gt-container .gt-link-project { + text-decoration: none; + } + .gt-container .gt-meta { + margin: 1.25em 0; + padding: 1em 0; + position: relative; + border-bottom: 1px solid #e9e9e9; + font-size: 1em; + position: relative; + z-index: 10; + } + .gt-container .gt-meta:before, + .gt-container .gt-meta:after { + content: " "; + display: table; + } + .gt-container .gt-meta:after { + clear: both; + } + .gt-container .gt-counts { + margin: 0 0.625em 0 0; + } + .gt-container .gt-user { + float: right; + margin: 0; + font-size: 92%; + } + .gt-container .gt-user-pic { + width: 16px; + height: 16px; + vertical-align: top; + margin-right: 0.5em; + } + .gt-container .gt-user-inner { + display: inline-block; + cursor: pointer; + } + .gt-container .gt-user .gt-ico { + margin: 0 0 0 0.3125em; + } + .gt-container .gt-user .gt-ico svg { + fill: inherit; + } + .gt-container .gt-user .is--poping .gt-ico svg { + fill: #6190e8; + } + .gt-container .gt-version { + color: #a1a1a1; + margin-left: 0.375em; + } + .gt-container .gt-copyright { + margin: 0 0.9375em 0.5em; + border-top: 1px solid #e9e9e9; + padding-top: 0.5em; + } + .gt-container .gt-popup { + position: absolute; + right: 0; + top: 2.375em; + background: #fff; + display: inline-block; + border: 1px solid #e9e9e9; + padding: 0.625em 0; + font-size: 0.875em; + letter-spacing: 0.5px; + } + .gt-container .gt-popup .gt-action { + cursor: pointer; + display: block; + margin: 0.5em 0; + padding: 0 1.125em; + position: relative; + text-decoration: none; + } + .gt-container .gt-popup .gt-action.is--active:before { + content: ''; + width: 0.25em; + height: 0.25em; + background: #6190e8; + position: absolute; + left: 0.5em; + top: 0.4375em; + } + .gt-container .gt-header { + position: relative; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + } + .gt-container .gt-header-comment { + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1; + margin-left: 1.25em; + } + @media (max-width: 479px) { + .gt-container .gt-header-comment { + margin-left: 0.875em; + } + } + .gt-container .gt-header-textarea { + padding: 0.75em; + display: block; + -webkit-box-sizing: border-box; + box-sizing: border-box; + width: 100%; + min-height: 5.125em; + max-height: 15em; + border-radius: 5px; + border: 1px solid rgba(0,0,0,0.1); + font-size: 0.875em; + word-wrap: break-word; + resize: vertical; + background-color: #f6f6f6; + outline: none; + -webkit-transition: all 0.25s ease; + transition: all 0.25s ease; + } + .gt-container .gt-header-textarea:hover { + background-color: #fbfbfb; + } + .gt-container .gt-header-preview { + padding: 0.75em; + border-radius: 5px; + border: 1px solid rgba(0,0,0,0.1); + background-color: #f6f6f6; + } + .gt-container .gt-header-controls { + position: relative; + margin: 0.75em 0 0; + } + .gt-container .gt-header-controls:before, + .gt-container .gt-header-controls:after { + content: " "; + display: table; + } + .gt-container .gt-header-controls:after { + clear: both; + } + @media (max-width: 479px) { + .gt-container .gt-header-controls { + margin: 0; + } + } + .gt-container .gt-header-controls-tip { + font-size: 0.875em; + color: #6190e8; + text-decoration: none; + vertical-align: sub; + } + @media (max-width: 479px) { + .gt-container .gt-header-controls-tip { + display: none; + } + } + .gt-container .gt-header-controls .gt-btn { + float: right; + margin-left: 1.25em; + } + @media (max-width: 479px) { + .gt-container .gt-header-controls .gt-btn { + float: none; + width: 100%; + margin: 0.75em 0 0; + } + } + .gt-container:after { + content: ''; + position: fixed; + bottom: 100%; + left: 0; + right: 0; + top: 0; + opacity: 0; + } + .gt-container.gt-input-focused { + position: relative; + } + .gt-container.gt-input-focused:after { + content: ''; + position: fixed; + bottom: 0%; + left: 0; + right: 0; + top: 0; + background: #000; + opacity: 0.6; + -webkit-transition: opacity 0.3s, bottom 0s; + transition: opacity 0.3s, bottom 0s; + z-index: 9999; + } + .gt-container.gt-input-focused .gt-header-comment { + z-index: 10000; + } + .gt-container .gt-comments { + padding-top: 1.25em; + } + .gt-container .gt-comments-null { + text-align: center; + } + .gt-container .gt-comments-controls { + margin: 1.25em 0; + text-align: center; + } + .gt-container .gt-comment { + position: relative; + padding: 0.625em 0; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + } + .gt-container .gt-comment-content { + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1; + margin-left: 1.25em; + padding: 0.75em 1em; + background-color: #f9f9f9; + overflow: auto; + -webkit-transition: all ease 0.25s; + transition: all ease 0.25s; + } + .gt-container .gt-comment-content:hover { + -webkit-box-shadow: 0 0.625em 3.75em 0 #f4f4f4; + box-shadow: 0 0.625em 3.75em 0 #f4f4f4; + } + @media (max-width: 479px) { + .gt-container .gt-comment-content { + margin-left: 0.875em; + padding: 0.625em 0.75em; + } + } + .gt-container .gt-comment-header { + margin-bottom: 0.5em; + font-size: 0.875em; + position: relative; + } + .gt-container .gt-comment-username { + font-weight: 500; + color: #6190e8; + text-decoration: none; + } + .gt-container .gt-comment-username:hover { + text-decoration: underline; + } + .gt-container .gt-comment-text { + margin-left: 0.5em; + color: #a1a1a1; + } + .gt-container .gt-comment-date { + margin-left: 0.5em; + color: #a1a1a1; + } + .gt-container .gt-comment-like, + .gt-container .gt-comment-edit, + .gt-container .gt-comment-reply { + position: absolute; + height: 1.375em; + } + .gt-container .gt-comment-like:hover, + .gt-container .gt-comment-edit:hover, + .gt-container .gt-comment-reply:hover { + cursor: pointer; + } + .gt-container .gt-comment-like { + top: 0; + right: 2em; + } + .gt-container .gt-comment-edit, + .gt-container .gt-comment-reply { + top: 0; + right: 0; + } + .gt-container .gt-comment-body { + color: #333 !important; + } + .gt-container .gt-comment-admin .gt-comment-content { + background-color: #f6f9fe; + } + @-webkit-keyframes gt-kf-rotate { + 0% { + -webkit-transform: rotate(0); + transform: rotate(0); + } + 100% { + -webkit-transform: rotate(360deg); + transform: rotate(360deg); + } + } + @keyframes gt-kf-rotate { + 0% { + -webkit-transform: rotate(0); + transform: rotate(0); + } + 100% { + -webkit-transform: rotate(360deg); + transform: rotate(360deg); + } + } + + /*# sourceMappingURL=gitalk.css.map*/ \ No newline at end of file diff --git a/css/highlight.css b/css/highlight.css new file mode 100644 index 0000000..37e1cc2 --- /dev/null +++ b/css/highlight.css @@ -0,0 +1,446 @@ +html { + -ms-text-size-adjust: 100%; +} + +article, aside, footer, header, nav, section { + display: block; +} + +figcaption, figure, main { + display: block; +} + +figure { + margin: 1em 40px; +} + +hr { + overflow: visible; +} + +a { + background-color: transparent; + -webkit-text-decoration-skip: object; +} + +mark { + background-color: #ff0; + color: #000; +} + +audio, video { + display: inline-block; +} + +img { + border-style: none; + max-width: 100%; +} + +svg:not(:root) { + overflow: hidden; +} + +button, input { + overflow: visible; +} + +button, select { + text-transform: none; +} + +legend { + box-sizing: border-box; + color: inherit; + display: table; + max-width: 100%; + white-space: normal; +} + +progress { + display: inline-block; +} +blockquote{ + background: #ecf0f1; + margin: 0; + padding: 2px 10px; + font-style: italic; + box-sizing: border-box; +} +textarea { + overflow: auto; +} + +[type="checkbox"], [type="radio"] { + box-sizing: border-box; + padding: 0; +} + +details, menu { + display: list-item; +} + +canvas { + display: inline-block; +} + +[type="search"]::-webkit-search-cancel-button, [type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +button, input, optgroup, select, textarea { + -webkit-appearance: none; + -webkit-tap-highlight-color: transparent; +} + +a { + -webkit-tap-highlight-color: transparent; +} + +/** + * Correct the style in all browsers. + */ +html { + font-family: "Helvetica Neue", Helvetica, STHeiTi, "Microsoft Yahei", sans-serif; + line-height: 1.15; + -webkit-text-size-adjust: 100%; +} + +body { + margin: 0; +} + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +hr { + box-sizing: content-box; + height: 0; +} + +pre { + overflow: scroll; + font-family: monospace, monospace; + font-size: 1em; +} + +a:active, a:hover { + outline-width: 0; +} + +abbr[title] { + border-bottom: none; + text-decoration: underline; + text-decoration: underline dotted; +} + +b, strong { + font-weight: bolder; +} + +code, kbd, samp { + font-family: monospace, monospace; + font-size: 1em; +} + +dfn { + font-style: italic; +} + +small { + font-size: 80%; +} + +sub, sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +audio:not([controls]) { + display: none; + height: 0; +} + +button, input, optgroup, select, textarea { + font-family: sans-serif; + font-size: 100%; + line-height: 1.15; + margin: 0; +} + +button, html [type="button"], [type="reset"], [type="submit"] { + -webkit-appearance: button; +} + +button::-moz-focus-inner, [type="button"]::-moz-focus-inner, [type="reset"]::-moz-focus-inner, [type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; +} + +button:-moz-focusring, [type="button"]:-moz-focusring, [type="reset"]:-moz-focusring, [type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; +} + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +legend { + padding: 0; +} + +progress { + vertical-align: baseline; +} + +[type="number"]::-webkit-inner-spin-button, [type="number"]::-webkit-outer-spin-button { + height: auto; +} + +[type="search"] { + -webkit-appearance: textfield; + outline-offset: -2px; +} + +::-webkit-file-upload-button { + -webkit-appearance: button; + font: inherit; +} + +details, summary { + display: list-item; +} + +code, +pre { + font-size: 0.8em; + background-color: #ecf0f1; + font-family: 'Roboto Mono', Monaco, courier, monospace; +} + +code { + padding: 0.1em 0.4em; + background-color: #ecf0f1; + border-radius: 3px; +} + +pre .line { + min-height: 1em; +} + +.highlight { + position: relative; + margin: 1em 0; + border-radius: 2px; + line-height: 1.1em; + background-color: #ecf0f1; + overflow-x: auto; + -webkit-overflow-scrolling: touch; +} +.highlight figcaption { + font-size: .9em; + padding: .4em; + border-bottom: 1px solid #bdc3c7; +} +.highlight table, .highlight tr, .highlight td { + width: 100%; + border-collapse: collapse; + padding: 0; + margin: 0; +} +.highlight .gutter { + display: none; +} +.highlight .code pre { + padding: 1.2em 1.4em; + line-height: 1.5em; + margin: 0; +} + +.highlight.html .code:after, .highlight.js .code:after, .highlight.bash .code:after, .highlight.css .code:after, .highlight.scss .code:after, .highlight.diff .code:after, .highlight.java .code:after, .highlight.xml .code:after, .highlight.python .code:after, .highlight.json .code:after, .highlight.swift .code:after, .highlight.ruby .code:after, .highlight.perl .code:after, .highlight.php .code:after, .highlight.c .code:after, .highlight.cpp .code:after, .highlight.ts .code:after { + position: absolute; + top: 0; + right: 0; + color: #bdc3c7; + text-align: right; + font-size: 0.75em; + padding: 5px 10px 0; + line-height: 15px; + height: 15px; + font-weight: 600; +} + +.highlight.html .code:after { + content: "HTML"; +} + +.highlight.js .code:after { + content: "JS"; +} + +.highlight.bash .code:after { + content: "BASH"; +} + +.highlight.css .code:after { + content: "CSS"; +} + +.highlight.scss .code:after { + content: "SCSS"; +} + +.highlight.diff .code:after { + content: "DIFF"; +} + +.highlight.java .code:after { + content: "JAVA"; +} + +.highlight.xml .code:after { + content: "XML"; +} + +.highlight.python .code:after { + content: "PYTHON"; +} + +.highlight.json .code:after { + content: "JSON"; +} + +.highlight.swift .code:after { + content: "SWIFT"; +} + +.highlight.ruby .code:after { + content: "RUBY"; +} + +.highlight.perl .code:after { + content: "PERL"; +} + +.highlight.php .code:after { + content: "PHP"; +} + +.highlight.c .code:after { + content: "C"; +} + +.highlight.java .code:after { + content: "JAVA"; +} + +.highlight.cpp .code:after { + content: "CPP"; +} + +.highlight.ts .code:after { + content: "TS"; +} + +.highlight.cpp .code:after { + content: 'C++'; +} + +pre { + color: #34495e; +} +pre .function .keyword, +pre .constant { + color: #3498db; +} +pre .keyword, +pre .attribute { + color: #e96900; +} +pre .number, +pre .literal { + color: #8e44ad; +} +pre .tag, +pre .tag .title, +pre .change, +pre .winutils, +pre .flow, +pre .lisp .title, +pre .clojure .built_in, +pre .nginx .title, +pre .tex .special { + color: #2980b9; +} +pre .symbol, +pre .symbol .string, +pre .value, +pre .regexp { + color: #1abc9c; +} +pre .title { + color: #2ecc71; +} +pre .tag .value, +pre .string, +pre .subst, +pre .haskell .type, +pre .preprocessor, +pre .ruby .class .parent, +pre .built_in, +pre .sql .aggregate, +pre .django .template_tag, +pre .django .variable, +pre .smalltalk .class, +pre .javadoc, +pre .django .filter .argument, +pre .smalltalk .localvars, +pre .smalltalk .array, +pre .attr_selector, +pre .pseudo, +pre .addition, +pre .stream, +pre .envvar, +pre .apache .tag, +pre .apache .cbracket, +pre .tex .command, +pre .prompt { + color: #1abc9c; +} +pre .comment, +pre .java .annotation, +pre .python .decorator, +pre .template_comment, +pre .pi, +pre .doctype, +pre .shebang, +pre .apache .sqbracket, +pre .tex .formula { + color: #95a5a6; +} +pre .deletion { + color: #c0392b; +} +pre .coffeescript .javascript, +pre .javascript .xml, +pre .tex .formula, +pre .xml .javascript, +pre .xml .vbscript, +pre .xml .css, +pre .xml .cdata { + opacity: 0.5; +} diff --git a/fly/Python入门/index.html b/fly/Python入门/index.html new file mode 100644 index 0000000..7c1f4ab --- /dev/null +++ b/fly/Python入门/index.html @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Python入门 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/fly/Python新特性/index.html b/fly/Python新特性/index.html new file mode 100644 index 0000000..321f61a --- /dev/null +++ b/fly/Python新特性/index.html @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + Python新特性 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/fly/自动化办公/index.html b/fly/自动化办公/index.html new file mode 100644 index 0000000..ae7db6e --- /dev/null +++ b/fly/自动化办公/index.html @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 自动化办公 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/fly/自然语言处理/index.html b/fly/自然语言处理/index.html new file mode 100644 index 0000000..8ea37ca --- /dev/null +++ b/fly/自然语言处理/index.html @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + 自然语言处理 | FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/images/bg.png b/images/bg.png new file mode 100644 index 0000000..b8045e4 Binary files /dev/null and b/images/bg.png differ diff --git a/images/bg_post.png b/images/bg_post.png new file mode 100644 index 0000000..a38c8f6 Binary files /dev/null and b/images/bg_post.png differ diff --git a/images/bg_sm.png b/images/bg_sm.png new file mode 100644 index 0000000..87ea058 Binary files /dev/null and b/images/bg_sm.png differ diff --git a/images/default_cover.jpg b/images/default_cover.jpg new file mode 100644 index 0000000..96b495a Binary files /dev/null and b/images/default_cover.jpg differ diff --git a/images/flypython.png b/images/flypython.png new file mode 100644 index 0000000..272c05c Binary files /dev/null and b/images/flypython.png differ diff --git a/images/new-01.png b/images/new-01.png new file mode 100644 index 0000000..985fc3b Binary files /dev/null and b/images/new-01.png differ diff --git a/images/new-02.png b/images/new-02.png new file mode 100644 index 0000000..beb5a20 Binary files /dev/null and b/images/new-02.png differ diff --git a/images/nlp1.png b/images/nlp1.png new file mode 100644 index 0000000..c2bcee2 Binary files /dev/null and b/images/nlp1.png differ diff --git a/images/oa1.jpg b/images/oa1.jpg new file mode 100644 index 0000000..f41d837 Binary files /dev/null and b/images/oa1.jpg differ diff --git a/images/oa2.jpg b/images/oa2.jpg new file mode 100644 index 0000000..57e1362 Binary files /dev/null and b/images/oa2.jpg differ diff --git a/images/oa3.jpg b/images/oa3.jpg new file mode 100644 index 0000000..bec3d58 Binary files /dev/null and b/images/oa3.jpg differ diff --git a/images/oa4.jpg b/images/oa4.jpg new file mode 100644 index 0000000..4e4efba Binary files /dev/null and b/images/oa4.jpg differ diff --git a/images/tutorial1.png b/images/tutorial1.png new file mode 100644 index 0000000..6884bd7 Binary files /dev/null and b/images/tutorial1.png differ diff --git a/images/tutorial2.png b/images/tutorial2.png new file mode 100644 index 0000000..6bd6e9e Binary files /dev/null and b/images/tutorial2.png differ diff --git a/images/tutorial3.png b/images/tutorial3.png new file mode 100644 index 0000000..fcb0991 Binary files /dev/null and b/images/tutorial3.png differ diff --git a/images/wechat.png b/images/wechat.png new file mode 100644 index 0000000..5fbf2e6 Binary files /dev/null and b/images/wechat.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..30e9105 --- /dev/null +++ b/index.html @@ -0,0 +1,270 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + FlyPython - 专业的Python学习社区 + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+ +
+
+
+
+ + + +
+ +
+ +
+ + + + +
+ +
+ + + + diff --git a/js/f25.js b/js/f25.js new file mode 100644 index 0000000..67732c5 --- /dev/null +++ b/js/f25.js @@ -0,0 +1,66 @@ +/** + * [删除ClassName] + * @param {*} element + * @param {*} className + */ +function removeClassName(element , className){ + if ( !hasClassName(element , className) ){ + return element; + } + element.className = ' ' + element.className.trim() + ' '; + element.className = element.className.replace(' ' + className + ' ' , ' ').trim(); + return element; +} +/** + * [添加className] + * @param {*} element + * @param {*} className + */ +function addClassName(element , className){ + if ( hasClassName(element , className) ){ + return element; + } + element.className = element.className.trim() + ' ' + className.trim(); + return element; +} + +/** + * [判断是否包含对应的className] + * @param {*} element + * @param {*} className + */ +function hasClassName(element , className){ + if ( (' ' + element.className.trim() + ' ').indexOf(' ' + className.trim() + ' ') >= 0 ){ + return true; + } + return false; +} + +/** + * [scrollToWindowTop 返回顶部] + * @return {[type]} [description] + */ +function scrollToWindowTop(){ + return window.scroll(0,0); +} + +var closeClassName = 'btn-close'; +var showClassName = 'show'; +var headerMenu = document.querySelector('#J_header_menu'); +var headerMenulist = document.querySelector('#J_header_menu_list'); + +if ( headerMenu && headerMenulist ){ + //h5菜单栏展示 + headerMenu.addEventListener('click' , (event)=>{ + event.preventDefault(); + event.stopPropagation(); + + if ( hasClassName(headerMenu , closeClassName) ){ + removeClassName(headerMenulist , showClassName); + removeClassName(headerMenu , closeClassName); + }else{ + addClassName(headerMenulist , showClassName); + addClassName(headerMenu , closeClassName); + } + }); +} \ No newline at end of file diff --git a/js/gitalk.min.js b/js/gitalk.min.js new file mode 100644 index 0000000..ca8338f --- /dev/null +++ b/js/gitalk.min.js @@ -0,0 +1,20 @@ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Gitalk=t():e.Gitalk=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist",t(t.s=75)}([function(e,t){var n=e.exports={version:"2.4.0"};"number"==typeof __e&&(__e=n)},function(e,t,n){var r=n(39)("wks"),o=n(24),i=n(2).Symbol,a="function"==typeof i;(e.exports=function(e){return r[e]||(r[e]=a&&i[e]||(a?i:o)("Symbol."+e))}).store=r},function(e,t){var n=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(e,t,n){"use strict";function r(e){return"[object Array]"===N.call(e)}function o(e){return"[object ArrayBuffer]"===N.call(e)}function i(e){return"undefined"!=typeof FormData&&e instanceof FormData}function a(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer}function u(e){return"string"==typeof e}function s(e){return"number"==typeof e}function c(e){return void 0===e}function l(e){return null!==e&&"object"==typeof e}function f(e){return"[object Date]"===N.call(e)}function p(e){return"[object File]"===N.call(e)}function d(e){return"[object Blob]"===N.call(e)}function h(e){return"[object Function]"===N.call(e)}function m(e){return l(e)&&h(e.pipe)}function v(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams}function g(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")}function y(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)}function b(e,t){if(null!==e&&void 0!==e)if("object"==typeof e||r(e)||(e=[e]),r(e))for(var n=0,o=e.length;n0;)n[r]=arguments[r+2];if(!g(e))return e;var o=e.attributes||e.props,i=G.h(e.nodeName||e.type,o,e.children||o&&o.children),a=[i,t];return n&&n.length?a.push(n):t&&t.children&&a.push(t.children),m(G.cloneElement.apply(void 0,a))}function g(e){return e&&(e instanceof q||e.$$typeof===z)}function y(e,t){return t._refProxies[e]||(t._refProxies[e]=function(n){t&&t.refs&&(t.refs[e]=n,null===n&&(delete t._refProxies[e],t=null))})}function b(e){var t=e.nodeName,n=e.attributes;if(n&&"string"==typeof t){var r={};for(var o in n)r[o.toLowerCase()]=o;if(r.ondoubleclick&&(n.ondblclick=n[r.ondoubleclick],delete n[r.ondoubleclick]),r.onchange&&("textarea"===t||"input"===t.toLowerCase()&&!/^fil|che|rad/i.test(n.type))){var i=r.oninput||"oninput";n[i]||(n[i]=T([n[i],n[r.onchange]]),delete n[r.onchange])}}}function _(e){var t=e.attributes;if(t){var n=t.className||t.class;n&&(t.className=n)}}function w(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}function x(e,t){for(var n in e)if(!(n in t))return!0;for(var r in t)if(e[r]!==t[r])return!0;return!1}function E(e){return e&&e.base||e}function N(){}function C(e){function t(e,t){A(this),I.call(this,e,t,Y),M.call(this,e,t)}return e=w({constructor:t},e),e.mixins&&O(e,S(e.mixins)),e.statics&&w(t,e.statics),e.propTypes&&(t.propTypes=e.propTypes),e.defaultProps&&(t.defaultProps=e.defaultProps),e.getDefaultProps&&(t.defaultProps=e.getDefaultProps()),N.prototype=I.prototype,t.prototype=w(new N,e),t.displayName=e.displayName||"Component",t}function S(e){for(var t={},n=0;n1)for(var n=1;n=t.length?{value:void 0,done:!0}:(e=r(t,n),this._i+=e.length,{value:e,done:!1})})},function(e,t){var n={}.toString;e.exports=function(e){return n.call(e).slice(8,-1)}},function(e,t,n){var r=n(35);e.exports=function(e){return Object(r(e))}},function(e,t){e.exports=!0},function(e,t){var n=0,r=Math.random();e.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+r).toString(36))}},function(e,t,n){var r=n(7).f,o=n(11),i=n(1)("toStringTag");e.exports=function(e,t,n){e&&!o(e=n?e:e.prototype,i)&&r(e,i,{configurable:!0,value:t})}},function(e,t,n){n(96);for(var r=n(2),o=n(10),i=n(16),a=n(1)("toStringTag"),u=["NodeList","DOMTokenList","MediaList","StyleSheetList","CSSRuleList"],s=0;s<5;s++){var c=u[s],l=r[c],f=l&&l.prototype;f&&!f[a]&&o(f,a,c),i[c]=i.Array}},function(e,t){t.f={}.propertyIsEnumerable},function(e,t){e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,t,n){var r=n(14),o=n(2).document,i=r(o)&&r(o.createElement);e.exports=function(e){return i?o.createElement(e):{}}},function(e,t,n){var r=n(14);e.exports=function(e,t){if(!r(e))return e;var n,o;if(t&&"function"==typeof(n=e.toString)&&!r(o=n.call(e)))return o;if("function"==typeof(n=e.valueOf)&&!r(o=n.call(e)))return o;if(!t&&"function"==typeof(n=e.toString)&&!r(o=n.call(e)))return o;throw TypeError("Can't convert object to primitive value")}},function(e,t,n){"use strict";function r(e){return function(){return e}}var o=function(){};o.thatReturns=r,o.thatReturnsFalse=r(!1),o.thatReturnsTrue=r(!0),o.thatReturnsNull=r(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(e){return e},e.exports=o},function(e,t,n){"use strict";(function(t){function n(e,t,n,o,i,a,u,s){if(r(t),!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[n,o,i,a,u,s],f=0;c=new Error(t.replace(/%s/g,function(){return l[f++]})),c.name="Invariant Violation"}throw c.framesToPop=1,c}}var r=function(e){};"production"!==t.env.NODE_ENV&&(r=function(e){if(void 0===e)throw new Error("invariant requires an error message argument")}),e.exports=n}).call(t,n(5))},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t){var n=Math.ceil,r=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?r:n)(e)}},function(e,t){e.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,n){var r=n(8),o=n(93),i=n(40),a=n(38)("IE_PROTO"),u=function(){},s=function(){var e,t=n(29)("iframe"),r=i.length;for(t.style.display="none",n(57).appendChild(t),t.src="javascript:",e=t.contentWindow.document,e.open(),e.write("