Skip to content

Commit 8cabc69

Browse files
committed
新增大量文章
1 parent 4bcc614 commit 8cabc69

16 files changed

+649
-0
lines changed

source/c02/c02_15.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 2.15 命令行式打开 idle 编辑脚本
2+
3+
![](http://image.iswbm.com/20200804124133.png)
4+
5+
在你安装 Python 解释器的时候,会有一个选项,让你选择是否安装 idle,这是一个极简的 Python 编辑器,对于有点 python 编码的经验的同学,一般都已经安装了更加专业的代码编辑器,比如 pycharm,vscode 等,所以一般是不会去勾选它的。
6+
7+
但是对于第一次接触 Python 编程的初学者来说,在自己的电脑上,大概率是没有安装代码编辑器的,这时候有一个现成的编辑器,可以尽快的将 hello world 跑起来,是一件非常重要的事情,因此初学者一般会被建议安装 idle,这也是为什么 idle 是大多数人的第一个 Python 代码编辑器。
8+
9+
在你安装了 idle 后,如果你使用 Windows 电脑,点击 py 文件会有使用 idle 打开的选项,非常方便你直接编辑 py 文件。
10+
11+
但如若你在 mac 电脑上,你的右键,是没有这个选项的,那如何使用 idle 打开编辑呢?
12+
13+
可以在终端上使用如下这条命令即可调用 idle 打开指定文件
14+
15+
```shell
16+
python3 -m idlelib unshelve.py
17+
```
18+
19+
使用的效果如下
20+
21+
![](http://image.iswbm.com/20210504110446.png)
22+
23+
如果你不加文件的路径,默认会打开 idle 的 shell 模式
24+
25+
![](http://image.iswbm.com/20210504110758.png)
26+
27+
28+
29+
![](http://image.iswbm.com/20200607174235.png)

source/c02/c02_15.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2.15 命令行式打开 idle 编辑脚本
2+
===============================
3+
4+
|image0|
5+
6+
在你安装 Python 解释器的时候,会有一个选项,让你选择是否安装
7+
idle,这是一个极简的 Python 编辑器,对于有点 python
8+
编码的经验的同学,一般都已经安装了更加专业的代码编辑器,比如
9+
pycharm,vscode 等,所以一般是不会去勾选它的。
10+
11+
但是对于第一次接触 Python
12+
编程的初学者来说,在自己的电脑上,大概率是没有安装代码编辑器的,这时候有一个现成的编辑器,可以尽快的将
13+
hello world 跑起来,是一件非常重要的事情,因此初学者一般会被建议安装
14+
idle,这也是为什么 idle 是大多数人的第一个 Python 代码编辑器。
15+
16+
在你安装了 idle 后,如果你使用 Windows 电脑,点击 py 文件会有使用 idle
17+
打开的选项,非常方便你直接编辑 py 文件。
18+
19+
但如若你在 mac 电脑上,你的右键,是没有这个选项的,那如何使用 idle
20+
打开编辑呢?
21+
22+
可以在终端上使用如下这条命令即可调用 idle 打开指定文件
23+
24+
.. code:: shell
25+
26+
python3 -m idlelib unshelve.py
27+
28+
使用的效果如下
29+
30+
|image1|
31+
32+
如果你不加文件的路径,默认会打开 idle 的 shell 模式
33+
34+
|image2|
35+
36+
|image3|
37+
38+
.. |image0| image:: http://image.iswbm.com/20200804124133.png
39+
.. |image1| image:: http://image.iswbm.com/20210504110446.png
40+
.. |image2| image:: http://image.iswbm.com/20210504110758.png
41+
.. |image3| image:: http://image.iswbm.com/20200607174235.png
42+

source/c02/c02_16.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# 2.16 快速计算字符串 base64编码
2+
3+
![](http://image.iswbm.com/20200804124133.png)
4+
5+
## 对字符串编码和解码
6+
7+
对一个字符串进行 base64 编码 和 解码(加上 `-d` 参数即可)
8+
9+
```shell
10+
$ echo "hello, world" | python3 -m base64
11+
aGVsbG8sIHdvcmxkCg==
12+
13+
$ echo "aGVsbG8sIHdvcmxkCg==" | python3 -m base64 -d
14+
hello, world
15+
```
16+
17+
效果如下
18+
19+
![](http://image.iswbm.com/20210504111702.png)
20+
21+
## 对文件进行编码和解码
22+
23+
在命令后面直接加文件的路径
24+
25+
```shell
26+
# 编码
27+
$ python3 -m base64 demo.py
28+
ZGVmIG1haW4oKToKICAgcHJpbnQoJ0hlbGxvIFdvcmxk8J+RjCcpCiAgIAppZiBfX25hbWVfXz09
29+
J19fbWFpbl9fJzoKICAgbWFpbigpCg==
30+
31+
# 解码
32+
$ echo "ZGVmIG1haW4oKToKICAgcHJpbnQoJ0hlbGxvIFdvcmxk8J+RjCcpCiAgIAppZiBfX25hbWVfXz09
33+
J19fbWFpbl9fJzoKICAgbWFpbigpCg==" | python3 -m base64 -d
34+
def main():
35+
print('Hello World👌')
36+
37+
if __name__=='__main__':
38+
main()
39+
```
40+
41+
效果如下
42+
43+
![](http://image.iswbm.com/20210504112153.png)
44+
45+
如果你的文件是 py 脚本的话,可以直接执行它
46+
47+
![](http://image.iswbm.com/20210504112257.png)
48+
49+
50+
51+
![](http://image.iswbm.com/20200607174235.png)

source/c02/c02_16.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2.16 快速计算字符串 base64编码
2+
==============================
3+
4+
|image0|
5+
6+
对字符串编码和解码
7+
------------------
8+
9+
对一个字符串进行 base64 编码 和 解码(加上 ``-d`` 参数即可)
10+
11+
.. code:: shell
12+
13+
$ echo "hello, world" | python3 -m base64
14+
aGVsbG8sIHdvcmxkCg==
15+
16+
$ echo "aGVsbG8sIHdvcmxkCg==" | python3 -m base64 -d
17+
hello, world
18+
19+
效果如下
20+
21+
|image1|
22+
23+
对文件进行编码和解码
24+
--------------------
25+
26+
在命令后面直接加文件的路径
27+
28+
.. code:: shell
29+
30+
# 编码
31+
$ python3 -m base64 demo.py
32+
ZGVmIG1haW4oKToKICAgcHJpbnQoJ0hlbGxvIFdvcmxk8J+RjCcpCiAgIAppZiBfX25hbWVfXz09
33+
J19fbWFpbl9fJzoKICAgbWFpbigpCg==
34+
35+
# 解码
36+
$ echo "ZGVmIG1haW4oKToKICAgcHJpbnQoJ0hlbGxvIFdvcmxk8J+RjCcpCiAgIAppZiBfX25hbWVfXz09
37+
J19fbWFpbl9fJzoKICAgbWFpbigpCg==" | python3 -m base64 -d
38+
def main():
39+
print('Hello World👌')
40+
41+
if __name__=='__main__':
42+
main()
43+
44+
效果如下
45+
46+
|image2|
47+
48+
如果你的文件是 py 脚本的话,可以直接执行它
49+
50+
|image3|
51+
52+
|image4|
53+
54+
.. |image0| image:: http://image.iswbm.com/20200804124133.png
55+
.. |image1| image:: http://image.iswbm.com/20210504111702.png
56+
.. |image2| image:: http://image.iswbm.com/20210504112153.png
57+
.. |image3| image:: http://image.iswbm.com/20210504112257.png
58+
.. |image4| image:: http://image.iswbm.com/20200607174235.png
59+

source/c02/c02_17.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 2.17 快速找到指定文件的mime类型
2+
3+
![](http://image.iswbm.com/20200804124133.png)
4+
5+
识别 html 文件
6+
7+
```shell
8+
# 可在线检测
9+
$ python -m mimetypes https://docs.python.org/3/library/mimetypes.html
10+
type: text/html encoding: None
11+
12+
# 也可离线检测(后面不再赘述)
13+
$ python -m mimetypes index.html
14+
type: text/html encoding: None
15+
```
16+
17+
识别图片格式
18+
19+
```shell
20+
$ python -m mimetypes https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png
21+
type: image/png encoding: None
22+
```
23+
24+
识别 Python 脚本
25+
26+
```shell
27+
$ python -m mimetypes sample.py
28+
type: text/x-python encoding: None # python文件
29+
```
30+
31+
识别压缩文件
32+
33+
```shell
34+
$ python -m mimetypes sample.py.gz
35+
type: text/x-python encoding: gzip # python文件,gzip压缩
36+
```
37+
38+
![](http://image.iswbm.com/20200607174235.png)

source/c02/c02_17.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2.17 快速找到指定文件的mime类型
2+
===============================
3+
4+
|image0|
5+
6+
识别 html 文件
7+
8+
.. code:: shell
9+
10+
# 可在线检测
11+
$ python -m mimetypes https://docs.python.org/3/library/mimetypes.html
12+
type: text/html encoding: None
13+
14+
# 也可离线检测(后面不再赘述)
15+
$ python -m mimetypes index.html
16+
type: text/html encoding: None
17+
18+
识别图片格式
19+
20+
.. code:: shell
21+
22+
$ python -m mimetypes https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png
23+
type: image/png encoding: None
24+
25+
识别 Python 脚本
26+
27+
.. code:: shell
28+
29+
$ python -m mimetypes sample.py
30+
type: text/x-python encoding: None # python文件
31+
32+
识别压缩文件
33+
34+
.. code:: shell
35+
36+
$ python -m mimetypes sample.py.gz
37+
type: text/x-python encoding: gzip # python文件,gzip压缩
38+
39+
|image1|
40+
41+
.. |image0| image:: http://image.iswbm.com/20200804124133.png
42+
.. |image1| image:: http://image.iswbm.com/20200607174235.png
43+

source/c02/c02_18.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 2.18 快速查看 Python 的环境信息
2+
3+
![](http://image.iswbm.com/20200804124133.png)
4+
5+
所有与 Python 相关的信息与配置,你都可以使用下面这条命令将其全部打印出来
6+
7+
```shell
8+
$ python -m sysconfig
9+
```
10+
11+
信息包括:
12+
13+
- 你当前的操作系统平台
14+
- Python 的具体版本
15+
- 包的搜索路径
16+
- 以及各种环境变量
17+
18+
![](http://image.iswbm.com/20210504114516.png)
19+
20+
![](http://image.iswbm.com/20200607174235.png)

source/c02/c02_18.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2.18 快速查看 Python 的环境信息
2+
===============================
3+
4+
|image0|
5+
6+
所有与 Python 相关的信息与配置,你都可以使用下面这条命令将其全部打印出来
7+
8+
.. code:: shell
9+
10+
$ python -m sysconfig
11+
12+
信息包括:
13+
14+
- 你当前的操作系统平台
15+
- Python 的具体版本
16+
- 包的搜索路径
17+
- 以及各种环境变量
18+
19+
|image1|
20+
21+
|image2|
22+
23+
.. |image0| image:: http://image.iswbm.com/20200804124133.png
24+
.. |image1| image:: http://image.iswbm.com/20210504114516.png
25+
.. |image2| image:: http://image.iswbm.com/20200607174235.png
26+

0 commit comments

Comments
 (0)