From 9159476d8f46f38c9217cc5fe2b1d2d75e52d1a5 Mon Sep 17 00:00:00 2001 From: iswbm Date: Mon, 7 Feb 2022 21:02:00 +0800 Subject: [PATCH 01/14] update --- md2rst.py | 22 ++++---------------- source/c01/c01_01.rst | 8 ++------ source/c01/c01_02.rst | 8 ++------ source/c01/c01_03.rst | 8 ++------ source/c01/c01_04.rst | 8 ++------ source/c01/c01_05.rst | 8 ++------ source/c01/c01_06.rst | 8 ++------ source/c01/c01_07.rst | 8 ++------ source/c01/c01_08.rst | 8 ++------ source/c01/c01_09.rst | 8 ++------ source/c01/c01_10.rst | 8 ++------ source/c01/c01_11.rst | 8 ++------ source/c01/c01_12.rst | 8 ++------ source/c01/c01_13.rst | 8 ++------ source/c01/c01_14.rst | 8 ++------ source/c01/c01_15.rst | 23 +++++++-------------- source/c01/c01_16.rst | 8 ++------ source/c01/c01_17.rst | 7 ++----- source/c01/c01_18.rst | 8 ++------ source/c01/c01_19.rst | 8 ++------ source/c01/c01_20.rst | 13 ++++-------- source/c01/c01_21.rst | 8 ++------ source/c01/c01_22.rst | 14 ++++--------- source/c01/c01_23.rst | 8 ++------ source/c01/c01_24.rst | 8 ++------ source/c01/c01_25.rst | 8 ++------ source/c01/c01_26.rst | 8 ++------ source/c01/c01_27.rst | 8 ++------ source/c01/c01_28.rst | 8 ++------ source/c01/c01_29.rst | 8 ++------ source/c01/c01_30.rst | 8 ++------ source/c01/c01_31.rst | 11 +++------- source/c01/c01_32.rst | 8 ++------ source/c02/c02_01.rst | 12 +++++------ source/c02/c02_02.rst | 8 ++------ source/c02/c02_03.rst | 8 ++------ source/c02/c02_04.rst | 8 ++------ source/c02/c02_05.rst | 8 ++------ source/c02/c02_06.rst | 11 +++------- source/c02/c02_07.rst | 11 +++------- source/c02/c02_08.rst | 8 ++------ source/c02/c02_09.rst | 11 +++------- source/c02/c02_10.rst | 14 ++++--------- source/c02/c02_11.rst | 17 +++++----------- source/c02/c02_12.rst | 25 ++++++++--------------- source/c02/c02_13.rst | 20 ++++++------------ source/c02/c02_14.rst | 17 +++++----------- source/c02/c02_15.rst | 14 ++++--------- source/c02/c02_16.rst | 17 +++++----------- source/c02/c02_17.rst | 8 ++------ source/c02/c02_18.rst | 11 +++------- source/c02/c02_19.rst | 8 ++------ source/c02/c02_20.rst | 8 ++------ source/c02/c02_21.rst | 8 ++------ source/c02/c02_22.rst | 14 ++++--------- source/c02/c02_23.rst | 8 ++------ source/c03/c03_01.rst | 8 ++------ source/c03/c03_02.rst | 8 ++------ source/c03/c03_03.rst | 8 ++------ source/c03/c03_04.rst | 8 ++------ source/c03/c03_05.rst | 8 ++------ source/c03/c03_06.rst | 11 +++------- source/c03/c03_07.rst | 8 ++------ source/c03/c03_08.rst | 20 ++++++------------ source/c03/c03_09.rst | 13 ++++-------- source/c03/c03_10.rst | 11 +++------- source/c03/c03_11.rst | 8 ++------ source/c03/c03_12.rst | 8 ++------ source/c04/c04_01.rst | 13 ++++-------- source/c04/c04_02.rst | 23 +++++++-------------- source/c04/c04_03.rst | 8 ++------ source/c05/c05_01.rst | 8 ++------ source/c05/c05_02.rst | 8 ++------ source/c05/c05_03.rst | 8 ++------ source/c05/c05_04.rst | 8 ++------ source/c05/c05_05.rst | 8 ++------ source/c05/c05_06.rst | 8 ++------ source/c05/c05_07.rst | 8 ++------ source/c05/c05_08.rst | 8 ++------ source/c05/c05_09.rst | 8 ++------ source/c05/c05_10.rst | 14 ++++--------- source/c05/c05_11.rst | 11 +++------- source/c05/c05_12.rst | 8 ++------ source/c05/c05_13.rst | 8 ++------ source/c05/c05_14.rst | 8 ++------ source/c05/c05_15.rst | 8 ++------ source/c05/c05_16.rst | 8 ++------ source/c05/c05_17.rst | 8 ++------ source/c05/c05_18.rst | 8 ++------ source/c05/c05_19.rst | 8 ++------ source/c05/c05_20.rst | 8 ++------ source/c05/c05_21.rst | 8 ++------ source/c05/c05_22.rst | 8 ++------ source/c05/c05_23.rst | 8 ++------ source/c05/c05_24.rst | 8 ++------ source/c05/c05_25.rst | 8 ++------ source/c05/c05_26.rst | 8 ++------ source/c05/c05_27.rst | 8 ++------ source/c05/c05_28.rst | 36 ++++++++++++--------------------- source/c05/c05_29.rst | 8 ++------ source/c05/c05_30.rst | 8 ++------ source/c05/c05_31.rst | 20 ++++++------------ source/c05/c05_32.rst | 8 ++------ source/c06/c06_01.rst | 8 ++------ source/c06/c06_02.rst | 11 +++------- source/c06/c06_03.rst | 8 ++------ source/c06/c06_04.rst | 19 ++++++----------- source/c06/c06_05.rst | 11 +++------- source/c06/c06_06.rst | 11 +++------- source/c06/c06_07.rst | 8 ++------ source/c06/c06_08.rst | 8 ++------ source/c06/c06_09.rst | 8 ++------ source/c06/c06_10.rst | 8 ++------ source/c06/c06_11.rst | 8 ++------ source/c06/c06_12.rst | 8 ++------ source/c07/c07_01.rst | 23 +++++++-------------- source/c07/c07_02.rst | 47 +++++++++++++++++-------------------------- source/c07/c07_03.rst | 8 ++------ source/c07/c07_04.rst | 47 +++++++++++++++++++------------------------ source/c07/c07_05.rst | 8 ++------ source/c07/c07_06.rst | 20 ++++++------------ source/c07/c07_07.rst | 11 +++------- source/c07/c07_08.rst | 8 ++------ source/c07/c07_09.rst | 8 ++------ source/c07/c07_10.rst | 14 ++++--------- source/c07/c07_11.rst | 8 ++------ source/c07/c07_12.rst | 19 ++++++----------- source/c07/c07_13.rst | 8 ++------ 128 files changed, 392 insertions(+), 1001 deletions(-) diff --git a/md2rst.py b/md2rst.py index 8567b15..14669d3 100644 --- a/md2rst.py +++ b/md2rst.py @@ -1,28 +1,14 @@ # coding:utf-8 import os -# import commands import subprocess import platform -from git import Repo - osName = platform.system() -repo_path ='.' -if (osName == 'Windows'): - repo_path = 'E:\\MING-Git\\magic-python' - blog_path = 'E:\\MING-Git\\magic-python\\source' - index_path = 'E:\\MING-Git\\magic-python\\README.md' -elif (osName == 'Darwin'): - repo_path = '/Users/MING/Github/magic-python/' - blog_path = '/Users/MING/Github/magic-python/source' - index_path = '/Users/MING/Github/magic-python/README.md' - - -repo = Repo.init(path=repo_path) -if not repo.is_dirty(): - # 没有文件变更 - os._exit(0) +pwd = os.getcwd() +blog_path = os.path.join(pwd, "source") +index_path = os.path.join(pwd, "README.md") + base_link = "http://python.iswbm.com/en/latest/" readme_header = ''' diff --git a/source/c01/c01_01.rst b/source/c01/c01_01.rst index c392c51..7b6449e 100644 --- a/source/c01/c01_01.rst +++ b/source/c01/c01_01.rst @@ -1,7 +1,7 @@ 1.1 默默无闻的省略号很好用 ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在Python中,一切皆对象,省略号也不例外。 @@ -62,8 +62,4 @@ $ python3 demo.py ok -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_02.rst b/source/c01/c01_02.rst index 488f13c..5757773 100644 --- a/source/c01/c01_02.rst +++ b/source/c01/c01_02.rst @@ -1,7 +1,7 @@ 1.2 使用 end 来结束代码块 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 有不少编程语言,循环、判断代码块需要用 end 标明结束,这样一定程度上会使代码逻辑更加清晰一点。 @@ -34,8 +34,4 @@ 10 10 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_03.rst b/source/c01/c01_03.rst index e1420ad..fd41366 100644 --- a/source/c01/c01_03.rst +++ b/source/c01/c01_03.rst @@ -1,7 +1,7 @@ 1.3 可直接运行的 zip 包 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 我们可以经常看到有 Python 包,居然可以以 zip 包进行发布,并且可以不用解压直接使用。 @@ -38,8 +38,4 @@ 5 [root@localhost ~]# -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_04.rst b/source/c01/c01_04.rst index ba81d2c..f112b88 100644 --- a/source/c01/c01_04.rst +++ b/source/c01/c01_04.rst @@ -1,7 +1,7 @@ 1.4 反斜杠的倔强: 不写最后 ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png ``\`` 在 Python 中的用法主要有两种 @@ -48,8 +48,4 @@ ^ SyntaxError: EOL while scanning string literal -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_05.rst b/source/c01/c01_05.rst index ca73f7a..862929e 100644 --- a/source/c01/c01_05.rst +++ b/source/c01/c01_05.rst @@ -1,7 +1,7 @@ 1.5 如何修改解释器提示符 ======================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 这个当做今天的一个小彩蛋吧。应该算是比较冷门的,估计知道的人很少了吧。 @@ -33,8 +33,4 @@ 0 1 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_06.rst b/source/c01/c01_06.rst index 86c4ca7..57951aa 100644 --- a/source/c01/c01_06.rst +++ b/source/c01/c01_06.rst @@ -1,7 +1,7 @@ 1.6 简洁而优雅的链式比较 ======================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 先给你看一个示例: @@ -28,8 +28,4 @@ 这个用法叫做链式比较。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_07.rst b/source/c01/c01_07.rst index e9e9b1a..ae88d08 100644 --- a/source/c01/c01_07.rst +++ b/source/c01/c01_07.rst @@ -1,7 +1,7 @@ 1.7 and 和 or 的短路效应 ======================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png and 和 or 是我们再熟悉不过的两个逻辑运算符,在 Python 也有它的妙用。 @@ -16,8 +16,4 @@ and 和 or 是我们再熟悉不过的两个逻辑运算符,在 Python 也有 >>>(2 or 3) * (5 and 6 and 7) 14 # 2*7 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_08.rst b/source/c01/c01_08.rst index bf54908..da110d4 100644 --- a/source/c01/c01_08.rst +++ b/source/c01/c01_08.rst @@ -1,7 +1,7 @@ 1.8 连接多个列表最极客的方式 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png .. code:: python @@ -12,8 +12,4 @@ >>> sum((a,b,c), []) [1, 2, 3, 4, 5, 6] -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_09.rst b/source/c01/c01_09.rst index 4c4e28e..0352919 100644 --- a/source/c01/c01_09.rst +++ b/source/c01/c01_09.rst @@ -1,7 +1,7 @@ 1.9 字典居然是可以排序的? ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在 Python 3.6 之前字典不可排序的思想,似乎已经根深蒂固。 @@ -24,8 +24,4 @@ >>> mydict {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4} -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_10.rst b/source/c01/c01_10.rst index d18579f..9747b73 100644 --- a/source/c01/c01_10.rst +++ b/source/c01/c01_10.rst @@ -1,7 +1,7 @@ 1.10 哪些情况下不需要续行符? ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在写代码时,为了代码的可读性,代码的排版是尤为重要的。 @@ -47,8 +47,4 @@ >>> text 'talk is cheap,\nshow me code.' -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_11.rst b/source/c01/c01_11.rst index 23f245a..de3258b 100644 --- a/source/c01/c01_11.rst +++ b/source/c01/c01_11.rst @@ -1,7 +1,7 @@ 1.11 用户无感知的小整数池 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 为避免整数频繁申请和销毁内存空间,Python 定义了一个小整数池 [-5, 256] 这些整数对象是提前建立好的,不会被垃圾回收。 @@ -34,8 +34,4 @@ 因为当你在同一行里,同时给两个变量赋同一值时,解释器知道这个对象已经生成,那么它就会引用到同一个对象。如果分成两行的话,解释器并不知道这个对象已经存在了,就会重新申请内存存放这个对象。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_12.rst b/source/c01/c01_12.rst index c9cbdab..421cad7 100644 --- a/source/c01/c01_12.rst +++ b/source/c01/c01_12.rst @@ -1,7 +1,7 @@ 1.12 神奇的 intern 机制 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 字符串类型作为Python中最常用的数据类型之一,Python解释器为了提高字符串使用的效率和使用性能,做了很多优化。 @@ -42,8 +42,4 @@ intern(字符串驻留)的技术来提高字符串效率,什么是intern >>> s1 is s2 False -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_13.rst b/source/c01/c01_13.rst index 24ea911..3886da0 100644 --- a/source/c01/c01_13.rst +++ b/source/c01/c01_13.rst @@ -1,7 +1,7 @@ 1.13 site-packages和 dist-packages ================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 如果你足够细心,你会在你的机器上,有些包是安装在 **site-packages** 下,而有些包安装在 **dist-packages** 下。 @@ -26,8 +26,4 @@ Debian 这么设计的原因,是为了减少不同来源的 Python 之间产 >>> print(get_python_lib()) /usr/lib/python2.7/site-packages -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_14.rst b/source/c01/c01_14.rst index 2fe2f94..6f4566c 100644 --- a/source/c01/c01_14.rst +++ b/source/c01/c01_14.rst @@ -1,7 +1,7 @@ 1.14 argument 和 parameter 的区别? ================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png arguments 和 parameter 的翻译都是参数,在中文场景下,二者混用基本没有问题,毕竟都叫参数嘛。 @@ -22,8 +22,4 @@ arguments 和 parameter output_msg("error") -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_15.rst b/source/c01/c01_15.rst index 990627a..1c0e0aa 100644 --- a/source/c01/c01_15.rst +++ b/source/c01/c01_15.rst @@ -1,7 +1,7 @@ 1.15 /usr/bin/env python 有什么用? =================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 我们经常会在别人的脚本或者项目的入口文件里看到第一行是下面这样 @@ -20,7 +20,7 @@ 稍微接触过 linux 的人都知道 ``/usr/bin/python`` 就是我们执行 ``python`` 进入console 模式里的 ``python`` -|image1| +.. image:: http://image.iswbm.com/20200331184021.png 而当你在可执行文件头里使用 ``#!`` + ``/usr/bin/python`` ,意思就是说你得用哪个软件 (python)来执行这个文件。 @@ -29,20 +29,20 @@ 不加的话,你每次执行这个脚本时,都得这样: ``python xx.py`` , -|image2| +.. image:: http://image.iswbm.com/20200331185034.png 有没有一种方式?可以省去每次都加 ``python`` 呢? 当然有,你可以文件头里加上\ ``#!/usr/bin/python`` ,那么当这个文件有可执行权限 时,只直接写这个脚本文件,就像下面这样。 -|image3| +.. image:: http://image.iswbm.com/20200331184755.png 明白了这个后,再来看看 ``!/usr/bin/env python`` 这个 又是什么意思 ? 当我执行 ``env python`` 时,自动进入了 python console 的模式。 -|image4| +.. image:: http://image.iswbm.com/20200331185741.png 这是为什么?和 直接执行 python 好像没什么区别呀 @@ -57,20 +57,11 @@ 具体演示过程,你可以看下面。 -|image5| +.. image:: http://image.iswbm.com/20200331190224.png 那么对于这两者,我们应该使用哪个呢? 个人感觉应该优先使用 ``#!/usr/bin/env python``\ ,因为不是所有的机器的 python 解释器都是 ``/usr/bin/python`` 。 -|image6| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200331184021.png -.. |image2| image:: http://image.iswbm.com/20200331185034.png -.. |image3| image:: http://image.iswbm.com/20200331184755.png -.. |image4| image:: http://image.iswbm.com/20200331185741.png -.. |image5| image:: http://image.iswbm.com/20200331190224.png -.. |image6| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_16.rst b/source/c01/c01_16.rst index a5f3935..4b1a960 100644 --- a/source/c01/c01_16.rst +++ b/source/c01/c01_16.rst @@ -1,7 +1,7 @@ 1.16 dict() 与 {} 生成空字典有什么区别? ======================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在初始化一个空字典时,有的人会写 dict(),而有的人会写成 {} @@ -55,8 +55,4 @@ 可以发现使用 dict(),会多了个调用函数的过程,而这个过程会有进出栈的操作,相对更加耗时。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_17.rst b/source/c01/c01_17.rst index 0c6b956..beee74f 100644 --- a/source/c01/c01_17.rst +++ b/source/c01/c01_17.rst @@ -1,7 +1,7 @@ 1.17 有趣但没啥用的 import 用法 =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png import 是 Python 导包的方式。 @@ -52,9 +52,6 @@ import 是 Python 导包的方式。 就会自动打开一个网页。 |image1| -|image2| +.. image:: http://image.iswbm.com/20200607174235.png -.. |image0| image:: http://image.iswbm.com/20200804124133.png .. |image1| image:: http://image.iswbm.com/20190511165735.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - diff --git a/source/c01/c01_18.rst b/source/c01/c01_18.rst index 1b00f6b..463cbc3 100644 --- a/source/c01/c01_18.rst +++ b/source/c01/c01_18.rst @@ -1,7 +1,7 @@ 1.18 正负得负,负负得正 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 从初中开始,我们就开始接触了\ ``负数`` ,并且都知道了\ ``负负得正`` 的思想。 @@ -22,8 +22,4 @@ Python 作为一门高级语言,它的编写符合人类的思维逻辑,包 >>> 5---3 2 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_19.rst b/source/c01/c01_19.rst index 3d21b69..b3e5e5b 100644 --- a/source/c01/c01_19.rst +++ b/source/c01/c01_19.rst @@ -1,7 +1,7 @@ 1.19 return不一定都是函数的终点 =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 众所周知,try...finally... 的用法是:不管try里面是正常执行还是有报异常,最终都能保证finally能够执行。 @@ -57,8 +57,4 @@ return 真的是直接被忽视,那当finally 下没有显式的 return 会直接覆盖 try 里的 return,而如果 finally 里没有 显式的 return,那么 try 里的 return 仍然有效。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_20.rst b/source/c01/c01_20.rst index bb252cc..96486de 100644 --- a/source/c01/c01_20.rst +++ b/source/c01/c01_20.rst @@ -1,7 +1,7 @@ 1.20 字符串里的缝隙是什么? =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在Python中求一个字符串里,某子字符(串)出现的次数。 @@ -31,9 +31,9 @@ 因此 对于 ``aabb`` 这个字符串在 Python 来看应该是这样的 -|image1| +.. image:: http://image.iswbm.com/20200509172331.png -理解了这个"**缝隙**" 的概念后,以下这些就好理解了。 +理解了这个"\ **缝隙**\ " 的概念后,以下这些就好理解了。 .. code:: python @@ -46,9 +46,4 @@ >>> "" in "M" True -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200509172331.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_21.rst b/source/c01/c01_21.rst index 08ec573..c1a86d5 100644 --- a/source/c01/c01_21.rst +++ b/source/c01/c01_21.rst @@ -1,7 +1,7 @@ 1.21 Python2下 也能使用 print("") ================================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 可能会有不少人,觉得只有 Python 3 才可以使用 print(),而 Python 2 只能使用\ ``print ""``\ 。 @@ -33,8 +33,4 @@ ,但是这仅用于两个 python 版本之间的代码兼容,并不是说在 python2.6+下使用 print() 后,就成了函数。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_22.rst b/source/c01/c01_22.rst index 6e2a3df..2dcdf75 100644 --- a/source/c01/c01_22.rst +++ b/source/c01/c01_22.rst @@ -1,7 +1,7 @@ 1.22 字母也玩起了障眼法 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 以下我分别在 Python2.7 和 Python 3.7 的 console 模式下,运行了如下代码。 @@ -25,11 +25,11 @@ 什么?没有截图你不信? -|image1| +.. image:: http://image.iswbm.com/20200509122954.png 如果你在自己的电脑上尝试一下,结果可能是这样的 -|image2| +.. image:: http://image.iswbm.com/20200509123107.png **怎么又好了呢?** @@ -52,10 +52,4 @@ 细思恐极,在这里可千万不要得罪同事们,万一离职的时候,对方把你项目里的 ``e`` 全局替换成 ``e``\ ,到时候你就哭去吧,肉眼根本看不出来嘛。 -|image3| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200509122954.png -.. |image2| image:: http://image.iswbm.com/20200509123107.png -.. |image3| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_23.rst b/source/c01/c01_23.rst index 3ccef50..83c2cad 100644 --- a/source/c01/c01_23.rst +++ b/source/c01/c01_23.rst @@ -1,7 +1,7 @@ 1.23 数值与字符串的比较 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在 Python2 中,数字可以与字符串直接比较。结果是数值永远比字符串小。 @@ -19,8 +19,4 @@ >>> 100000000 < "" TypeError: '<' not supported between instances of 'int' and 'str' -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_24.rst b/source/c01/c01_24.rst index 1c65ed7..4fa42ea 100644 --- a/source/c01/c01_24.rst +++ b/source/c01/c01_24.rst @@ -1,7 +1,7 @@ 1.24 时有时无的切片异常 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 这是个简单例子,alist 只有5 个元素,当你取第 6 个元素时,会抛出索引异常。这与我们的认知一致。 @@ -25,8 +25,4 @@>>> alist[100:] [] -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_25.rst b/source/c01/c01_25.rst index 139421e..a6a357b 100644 --- a/source/c01/c01_25.rst +++ b/source/c01/c01_25.rst @@ -1,7 +1,7 @@ 1.25 迷一样的字符串 =================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 示例一 @@ -56,8 +56,4 @@ >>> 'a' * 21 is 'aaaaaaaaaaaaaaaaaaaaa' True -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_26.rst b/source/c01/c01_26.rst index f931fef..4ff81d9 100644 --- a/source/c01/c01_26.rst +++ b/source/c01/c01_26.rst @@ -1,7 +1,7 @@ 1.26 x 与 +x 等价吗? ===================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在大多数情况下,这个等式是成立的。 @@ -33,8 +33,4 @@ >>> +ct Counter({'a': 3, 'b': 2}) -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_27.rst b/source/c01/c01_27.rst index 8fbcb37..00a9bcc 100644 --- a/source/c01/c01_27.rst +++ b/source/c01/c01_27.rst @@ -1,7 +1,7 @@ 1.27 += 不等同于=+ ================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 对列表 进行\ ``+=`` 操作相当于 extend,而使用 ``=+`` 操作是新增了一个列表。 @@ -29,8 +29,4 @@ >>> b [1, 2, 3, 4, 5, 6, 7, 8] -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_28.rst b/source/c01/c01_28.rst index 0aee763..b5e1f46 100644 --- a/source/c01/c01_28.rst +++ b/source/c01/c01_28.rst @@ -1,7 +1,7 @@ 1.28 循环中的局部变量泄露 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在Python 2中 x 的值在一个循环执行之后被改变了。 @@ -25,8 +25,4 @@ >>> x 1 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_29.rst b/source/c01/c01_29.rst index e049b89..a84061b 100644 --- a/source/c01/c01_29.rst +++ b/source/c01/c01_29.rst @@ -1,7 +1,7 @@ 1.29 局部/全局变量傻傻分不清 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在开始讲之前,你可以试着运行一下下面这小段代码。 @@ -50,8 +50,4 @@ $ python demo.py 1 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_30.rst b/source/c01/c01_30.rst index ce56735..19de541 100644 --- a/source/c01/c01_30.rst +++ b/source/c01/c01_30.rst @@ -1,7 +1,7 @@ 1.30 break /continue 和 上下文管理器哪个优先级高? ================================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 众所周知,在循环体中(无论是 for 还是 while),continue 会用来跳入下一个循环,而 break 则用来跳出某个循环体。 @@ -54,8 +54,4 @@ print 来替代)。 1. continue 与 break 一样,如果先遇到上下文管理器会先进行资源的释放 2. 上面只举例了 while 循环体,而 for 循环也是同样的。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_31.rst b/source/c01/c01_31.rst index 5faadc1..eecd121 100644 --- a/source/c01/c01_31.rst +++ b/source/c01/c01_31.rst @@ -1,7 +1,7 @@ 1.31 如何像 awk一样分割字符串? =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 若你使用过 Shell 中的 awk 工具,会发现用它来分割字符串是非常方便的。特别是多个连续空格会被当做一个处理。 @@ -68,7 +68,7 @@ split函数不加参数,就能达到 awk 的效果 查看了注释,原来是这个函数会适配 None 的情况,当第一个参数是None的时候,返回第二个参数(可迭代对象)中非空的值,非常方便。 -|image1| +.. image:: http://image.iswbm.com/20200821173708.png 换用函数的写法,可以这样 @@ -81,9 +81,4 @@ split函数不加参数,就能达到 awk 的效果 >>> filter(lambda item: True if item else False, msg.split('-')) ['hello', 'world'] -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200821173708.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_32.rst b/source/c01/c01_32.rst index 96c6234..cb1067f 100644 --- a/source/c01/c01_32.rst +++ b/source/c01/c01_32.rst @@ -1,7 +1,7 @@ 1.32 如何让大数变得更易于阅读? =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当一个数非常大时,可能过百万,也可能上亿,太多位的数字 ,会给我们阅读带来很大的障碍。 @@ -28,8 +28,4 @@ >>> number 281028344 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_01.rst b/source/c02/c02_01.rst index a854371..210630b 100644 --- a/source/c02/c02_01.rst +++ b/source/c02/c02_01.rst @@ -1,5 +1,7 @@ -2.1 懒人必备技能:使用 "_" |image0| -=================================== +2.1 懒人必备技能:使用 "_" +========================== + +.. image:: http://image.iswbm.com/20200804124133.png 对于 ``_`` ,大家对于他的印象都是用于 **占位符**\ ,省得为一个不需要用到的变量,绞尽脑汁的想变量名。 @@ -63,8 +65,4 @@ 知道这两个魔法方法的人,一看就明白了,这里不再解释啦。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_02.rst b/source/c02/c02_02.rst index e09eced..1c6a46c 100644 --- a/source/c02/c02_02.rst +++ b/source/c02/c02_02.rst @@ -1,7 +1,7 @@ 2.2 最快查看包搜索路径的方式 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你使用 import 导入一个包或模块时,Python 会去一些目录下查找,而这些目录是有优先级顺序的,正常人会使用 sys.path @@ -63,8 +63,4 @@ 从输出你可以发现,这个列的路径会比 sys.path 更全,它包含了用户环境的目录。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_03.rst b/source/c02/c02_03.rst index b15223a..e1b103e 100644 --- a/source/c02/c02_03.rst +++ b/source/c02/c02_03.rst @@ -1,7 +1,7 @@ 2.3 使用 json.tool 来格式化 JSON ================================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 假设现在你需要查看你机器上的json文件,而这个文件没有经过任何的美化,阅读起来是非常困难的。 @@ -61,8 +61,4 @@ ] } -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_04.rst b/source/c02/c02_04.rst index 6c06e0a..1563d46 100644 --- a/source/c02/c02_04.rst +++ b/source/c02/c02_04.rst @@ -1,7 +1,7 @@ 2.4 命令行式执行 Python 代码 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 有时候你只是想验证一小段 Python 代码是否可用时,通常有两种方法 @@ -17,8 +17,4 @@ 只要加 -c 参数,就可以输入你的 Python 代码了。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_05.rst b/source/c02/c02_05.rst index b84daff..9ac5a69 100644 --- a/source/c02/c02_05.rst +++ b/source/c02/c02_05.rst @@ -1,7 +1,7 @@ 2.5 用调试模式执行脚本 ====================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你使用 pdb 进行脚本的调试时,你可能会先在目标代码处输入 ``import pdb;pdb.set_trace()`` 来设置断点。 @@ -15,8 +15,4 @@ -> import sys (Pdb) -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_06.rst b/source/c02/c02_06.rst index 94ce3c7..fe07dc9 100644 --- a/source/c02/c02_06.rst +++ b/source/c02/c02_06.rst @@ -1,7 +1,7 @@ 2.6 如何快速搭建 HTTP 服务器 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 搭建FTP,或者是搭建网络文件系统,这些方法都能够实现Linux的目录共享。但是FTP和网络文件系统的功能都过于强大,因此它们都有一些不够方便的地方。比如你想快速共享Linux系统的某个目录给整个项目团队,还想在一分钟内做到,怎么办?很简单,使用Python中的SimpleHTTPServer。 @@ -17,13 +17,8 @@ SimpleHTTPServer是Python # python3 python3 -m http.server 8888 -|image1| +.. image:: http://image.iswbm.com/20190511165716.png SimpleHTTPServer有一个特性,如果待共享的目录下有index.html,那么index.html文件会被视为默认主页;如果不存在index.html文件,那么就会显示整个目录列表。 -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20190511165716.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_07.rst b/source/c02/c02_07.rst index 0eaf0ec..f7b8424 100644 --- a/source/c02/c02_07.rst +++ b/source/c02/c02_07.rst @@ -1,7 +1,7 @@ 2.7 快速构建 HTML 帮助文档 ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你不知道一个内置模块如何使用时,会怎么做呢? @@ -23,11 +23,6 @@ 帮助文档的效果如下 -|image1| - -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200718191249.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20200718191249.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_08.rst b/source/c02/c02_08.rst index d98da9b..da5a668 100644 --- a/source/c02/c02_08.rst +++ b/source/c02/c02_08.rst @@ -1,7 +1,7 @@ 2.8 最正确且优雅的装包方法 ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你使用 pip 来安装第三方的模块时,通常会使用这样的命令 @@ -32,8 +32,4 @@ Python3.9,那你安装包时就会很困惑,我到底把包安装在了哪 # 在 python3.9 中安装 $ python3.9 -m pip install requests -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_09.rst b/source/c02/c02_09.rst index ffe7697..ae86a7c 100644 --- a/source/c02/c02_09.rst +++ b/source/c02/c02_09.rst @@ -1,7 +1,7 @@ 2.9 往 Python Shell 中传入参数 ============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 往一个 Python 脚本传入参数,是一件非常简单的事情。 @@ -17,11 +17,6 @@ 经过我的摸索,终于找到了方法,具体方法如下: -|image1| - -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200801195158.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20200801195158.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_10.rst b/source/c02/c02_10.rst index c64afca..e4817d0 100644 --- a/source/c02/c02_10.rst +++ b/source/c02/c02_10.rst @@ -1,7 +1,7 @@ 2.10 让脚本报错后立即进入调试模式 ================================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你在使用 ``python xxx.py`` 这样的方法,执行 Python 脚本时,若因为代码 bug 导致异常未捕获,那整个程序便会终止退出。 @@ -23,7 +23,7 @@ Shell 模式,方便你进行调试。 具体演示如下: -|image1| +.. image:: http://image.iswbm.com/20200801195950.png 需要注意的是:脚本执行完毕,有两种情况: @@ -33,14 +33,8 @@ Shell 模式,方便你进行调试。 这两种都会进入 Python Shell,如果脚本并无异常,最终也会进入 Python Shell 模式,需要你手动退出 -|image2| +.. image:: http://image.iswbm.com/20200801201110.png 如果希望脚本正确完成时自动退出,可以在脚本最后加上一行\ ``__import__("os")._exit(0)`` -|image3| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200801195950.png -.. |image2| image:: http://image.iswbm.com/20200801201110.png -.. |image3| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_11.rst b/source/c02/c02_11.rst index f067548..6fc242d 100644 --- a/source/c02/c02_11.rst +++ b/source/c02/c02_11.rst @@ -1,28 +1,21 @@ 2.11 极简模式执行 Python Shell ============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在终端输入 Python 就会进入 Python Shell 。 方便是挺方便,就是有点说不出的难受,谁能告诉我,为什么要多出这么大一段无关的内容。 -|image1| +.. image:: http://image.iswbm.com/20200801202733.png 这有点像,你上爱某艺看视频吧,都要先看个 90 秒的广告。 如果你和我一样不喜欢这种 『牛皮癣』,那么可以加个 ``-q`` 参数,静默进入 Python Shell,就像下面这样子,开启了极简模式,舒服多了。 -|image2| +.. image:: http://image.iswbm.com/20200801203047.png -|image3| - -|image4| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200801202733.png -.. |image2| image:: http://image.iswbm.com/20200801203047.png -.. |image3| image:: http://image.iswbm.com/20200512125643.png -.. |image4| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20200512125643.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_12.rst b/source/c02/c02_12.rst index e9625ce..7b56f56 100644 --- a/source/c02/c02_12.rst +++ b/source/c02/c02_12.rst @@ -1,9 +1,9 @@ 2.12 在执行任意代码前自动念一段平安经 ===================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png -最近的"平安经"可谓是引起了不小的风波啊。 +最近的"平安经"可谓是引起了不小的风波啊。 作为一个正儿八经的程序员,最害怕的就是自己的代码上线出现各种各样的 BUG。 @@ -16,7 +16,7 @@ 我要开始作妖了,噢不,是开始念经了。 -|image1| +.. image:: http://image.iswbm.com/20200801221705.png 感谢佛祖保佑,Everything is ok,No bugs in the code. @@ -34,7 +34,7 @@ 我们需要新建一个用户环境目录,这个目录比较长,不需要你死记硬背,使用 site 模块的方法就可以获取,然后使用 ``mkdir -p`` 命令创建它。 -|image2| +.. image:: http://image.iswbm.com/20200801220819.png 在这个目录下,新建一个 ``usercustomize.py`` 文件,注意名字必须是这个,换成其他的可就识别不到啦。 @@ -42,29 +42,20 @@ site 模块的方法就可以获取,然后使用 ``mkdir -p`` 命令创建它 这个 ``usercustomize.py`` 的内容如下(明哥注:佛祖只保佑几个 Python 的主要应用方向,毕竟咱是 Python 攻城狮嘛...) -|image3| +.. image:: http://image.iswbm.com/20200801221413.png 这个文件我放在了我的 github 上,点击\ `这里 `__\ 直达。 一切都完成后,无论你是使用 ``python xxx.py`` 执行脚本 -|image4| +.. image:: http://image.iswbm.com/20200801221705.png 还是使用 ``python`` 进入 Python Shell ,都会先念一下平安经保平安。 -|image5| +.. image:: http://image.iswbm.com/20200801221457.png 另外,有读者反馈这种设置会导致在Win10环境下 VSCode不能正常识别已安装的Python环境,并报出代码有导包错误等问题,因此请在你知道你自己在做什么,会千万什么后果,否则请在体验后还原你的环境。 -|image6| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200801221705.png -.. |image2| image:: http://image.iswbm.com/20200801220819.png -.. |image3| image:: http://image.iswbm.com/20200801221413.png -.. |image4| image:: http://image.iswbm.com/20200801221705.png -.. |image5| image:: http://image.iswbm.com/20200801221457.png -.. |image6| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_13.rst b/source/c02/c02_13.rst index 27e1053..647adaf 100644 --- a/source/c02/c02_13.rst +++ b/source/c02/c02_13.rst @@ -1,7 +1,7 @@ 2.13 启动 Python Shell 前自动执行某脚本 ======================================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 前一节我们介绍了一种,只要运行解释器就会自动触发执行 Python 脚本的方法。 @@ -13,7 +13,7 @@ 目录下并没有 ``usercustomize.py`` 文件,但是在执行 python 进入 Python Shell 模式后,还是会打印平安经。 -|image1| +.. image:: http://image.iswbm.com/20200801225652.png 这是如何做到的呢? @@ -22,7 +22,7 @@ Shell 模式后,还是会打印平安经。 第一件事,在任意你喜欢的目录下,新建 一个Python 脚本,名字也随意,比如我叫 ``startup.py``\ ,内容还是和上面一样 -|image2| +.. image:: http://image.iswbm.com/20200801221413.png 第二件事,设置一个环境变量 PYTHONSTARTUP,指向你的脚本路径 @@ -34,19 +34,11 @@ Shell 模式后,还是会打印平安经。 但是这种方法只适用于 Python Shell ,并不适用于 Python 执行脚本的方法。 -|image3| +.. image:: http://image.iswbm.com/20200801230230.png 如果要在脚本中实现这种效果,我目前想到最粗糙我笨拙的方法了 – ``手动加载执行`` -|image4| - -|image5| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200801225652.png -.. |image2| image:: http://image.iswbm.com/20200801221413.png -.. |image3| image:: http://image.iswbm.com/20200801230230.png -.. |image4| image:: http://image.iswbm.com/20200801230503.png -.. |image5| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20200801230503.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_14.rst b/source/c02/c02_14.rst index 2481894..07249c5 100644 --- a/source/c02/c02_14.rst +++ b/source/c02/c02_14.rst @@ -1,7 +1,7 @@ 2.14 把模块当做脚本来执行 7 种方法及原理 ======================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1. 用法举例 ----------- @@ -74,7 +74,7 @@ Python 先看一下 ``pip`` 的源码目录,发现在其下有一个 ``__main__.py`` 的文件,难道这是 ``-m`` 的入口? -|image1| +.. image:: http://image.iswbm.com/20200811155234.png 再看一下 ``json.tool`` 的源码文件,json 库下面却没有 ``__main__.py`` 的文件。 @@ -85,7 +85,7 @@ Python 查看 tool 模块的源代码,有一个名为 main 的函数 -|image2| +.. image:: http://image.iswbm.com/20200811154945.png 但它这不是关键,main 函数是在模块中直接被调用的。 @@ -146,7 +146,7 @@ Python 执行过程如下: -|image3| +.. image:: http://image.iswbm.com/20200811184733.png 再来验证一下使用第二种方法。 @@ -196,11 +196,4 @@ Python 的包导入机制会帮你做这些事情。 如此一对比,哪个更方便?你心里应该有数了。 -|image4| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200811155234.png -.. |image2| image:: http://image.iswbm.com/20200811154945.png -.. |image3| image:: http://image.iswbm.com/20200811184733.png -.. |image4| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_15.rst b/source/c02/c02_15.rst index c32b255..0782a8c 100644 --- a/source/c02/c02_15.rst +++ b/source/c02/c02_15.rst @@ -1,7 +1,7 @@ 2.15 命令行式打开 idle 编辑脚本 =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在你安装 Python 解释器的时候,会有一个选项,让你选择是否安装 idle,这是一个极简的 Python 编辑器,对于有点 python @@ -27,16 +27,10 @@ idle,这也是为什么 idle 是大多数人的第一个 Python 代码编辑 使用的效果如下 -|image1| +.. image:: http://image.iswbm.com/20210504110446.png 如果你不加文件的路径,默认会打开 idle 的 shell 模式 -|image2| - -|image3| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20210504110446.png -.. |image2| image:: http://image.iswbm.com/20210504110758.png -.. |image3| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20210504110758.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_16.rst b/source/c02/c02_16.rst index a0b1060..fae57d6 100644 --- a/source/c02/c02_16.rst +++ b/source/c02/c02_16.rst @@ -1,7 +1,7 @@ 2.16 快速计算字符串 base64编码 ============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 对字符串编码和解码 ------------------ @@ -18,7 +18,7 @@ 效果如下 -|image1| +.. image:: http://image.iswbm.com/20210504111702.png 对文件进行编码和解码 -------------------- @@ -43,17 +43,10 @@ 效果如下 -|image2| +.. image:: http://image.iswbm.com/20210504112153.png 如果你的文件是 py 脚本的话,可以直接执行它 -|image3| - -|image4| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20210504111702.png -.. |image2| image:: http://image.iswbm.com/20210504112153.png -.. |image3| image:: http://image.iswbm.com/20210504112257.png -.. |image4| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20210504112257.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_17.rst b/source/c02/c02_17.rst index ce2bb56..0c17a17 100644 --- a/source/c02/c02_17.rst +++ b/source/c02/c02_17.rst @@ -1,7 +1,7 @@ 2.17 快速找到指定文件的mime类型 =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 识别 html 文件 @@ -36,8 +36,4 @@ $ python -m mimetypes sample.py.gz type: text/x-python encoding: gzip # python文件,gzip压缩 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_18.rst b/source/c02/c02_18.rst index 003cb43..a0d3d01 100644 --- a/source/c02/c02_18.rst +++ b/source/c02/c02_18.rst @@ -1,7 +1,7 @@ 2.18 快速查看 Python 的环境信息 =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 所有与 Python 相关的信息与配置,你都可以使用下面这条命令将其全部打印出来 @@ -16,11 +16,6 @@ - 包的搜索路径 - 以及各种环境变量 -|image1| - -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20210504114516.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20210504114516.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_19.rst b/source/c02/c02_19.rst index 448d3ee..50041df 100644 --- a/source/c02/c02_19.rst +++ b/source/c02/c02_19.rst @@ -1,7 +1,7 @@ 2.19 快速解压和压缩文件 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png tar 格式压缩包 -------------- @@ -86,8 +86,4 @@ zip 格式压缩包 drwxr-xr-x 3 MING staff 96 5 4 12:57 demo -rw-r--r-- 1 MING staff 74890 5 4 12:55 demo.zip -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_20.rst b/source/c02/c02_20.rst index 9fe874a..e68b207 100644 --- a/source/c02/c02_20.rst +++ b/source/c02/c02_20.rst @@ -1,7 +1,7 @@ 2.20 快速编辑 Python 脚本 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png pyc是一种二进制文件,是由py文件经过编译后,生成的文件,是一种byte code,py文件变成pyc文件后,加载的速度会有所提高。因此在一些场景下,可以预先编译成 @@ -25,8 +25,4 @@ pyc 文件,来提高加载速度。 │ └── main.cpython-39.opt-1.pyc └── main.py -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_21.rst b/source/c02/c02_21.rst index 4d5f6eb..9b94aa6 100644 --- a/source/c02/c02_21.rst +++ b/source/c02/c02_21.rst @@ -1,7 +1,7 @@ 2.21 使用自带的 telnet 端口检测工具 =================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 若你想检测指定的机器上有没有开放某端口,但本机并没有安装 telnet 工具,不如尝试一下 python 自带的 telnetlib 库,亦可实现你的需求。 @@ -20,8 +20,4 @@ Telnet(192.168.56.200,22): recv b'' *** Connection closed by remote host *** -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_22.rst b/source/c02/c02_22.rst index f129ad4..394fd9d 100644 --- a/source/c02/c02_22.rst +++ b/source/c02/c02_22.rst @@ -1,11 +1,11 @@ 2.22 快速将项目打包成应用程序 ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 假设我当前有一个 demo 项目,目录结构树及相关文件的的代码如下 -|image1| +.. image:: http://image.iswbm.com/20210504133550.png 现在我使用如下命令,将该项目进行打包,其中 demo 是项目的文件夹名,\ ``main:main`` 中的第一个 main 指的 @@ -19,12 +19,6 @@ 具体演示过程如下 -|image2| - -|image3| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20210504133550.png -.. |image2| image:: http://image.iswbm.com/20210504133711.png -.. |image3| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20210504133711.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_23.rst b/source/c02/c02_23.rst index f716a41..b1726ff 100644 --- a/source/c02/c02_23.rst +++ b/source/c02/c02_23.rst @@ -1,7 +1,7 @@ 2.23 快速打印函数的调用栈 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在使用pdb时,手动打印调用栈 @@ -28,8 +28,4 @@ -> self.handle_one_response() /usr/lib/python2.7/site-packages/eventlet/wsgi.py(481)handle_one_response() -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_01.rst b/source/c03/c03_01.rst index f6efaf3..cca4068 100644 --- a/source/c03/c03_01.rst +++ b/source/c03/c03_01.rst @@ -1,7 +1,7 @@ 3.1 八种连接列表的方式 ====================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1、最直观的相加 --------------- @@ -190,8 +190,4 @@ heapq.merge,因为它采用堆排序,效率非常高。但若你不希望得 [1, 2, 3, 4, 5, 6, 7, 8, 9] >> -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_02.rst b/source/c03/c03_02.rst index 65fe60b..14d42ad 100644 --- a/source/c03/c03_02.rst +++ b/source/c03/c03_02.rst @@ -1,7 +1,7 @@ 3.2 合并字典的 7 种方法 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1、最简单的原地更新 ------------------- @@ -207,8 +207,4 @@ Operator),用它可以很直观地合并多个字典。 7 种合并字典的方法,实际在工作中,你只要选用一种最顺手的方式即可,但是在协同工作中,或者在阅读他人代码时,你不可避免地会碰到各式各样的写法,这时候你能下意识地知道这是在做合并字典的操作,那这篇文章就是有意义的。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_03.rst b/source/c03/c03_03.rst index 4330464..3e59131 100644 --- a/source/c03/c03_03.rst +++ b/source/c03/c03_03.rst @@ -1,7 +1,7 @@ 3.3 花式导包的八种方法 ====================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1. 直接 import -------------- @@ -302,8 +302,4 @@ python 文件,如果后面导入成功会打印 ``ok``\ 。 这种方法足够了,而对于那些想要自己开发框架的人来说,深入学习\ ``__import__``\ 以及 importlib 是非常有必要的。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_04.rst b/source/c03/c03_04.rst index 82d83da..21a3565 100644 --- a/source/c03/c03_04.rst +++ b/source/c03/c03_04.rst @@ -1,7 +1,7 @@ 3.4 条件语句的七种写法 ====================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 第一种:原代码 -------------- @@ -158,8 +158,4 @@ Python 功力。 看到这里,有没有涨姿势了,学了这么久的 Python ,这么多骚操作,还真是活久见。。这六种写法里,我最推荐使用的是第一种,自己也经常在用,简洁直白,代码行还少。而其他的写法虽然能写,但是不会用,也不希望在我余生里碰到会在公共代码里用这些写法的同事。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_05.rst b/source/c03/c03_05.rst index a83e0d2..4cf5fc6 100644 --- a/source/c03/c03_05.rst +++ b/source/c03/c03_05.rst @@ -1,7 +1,7 @@ 3.5 判断是否包含子串的七种方法 ============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1、使用 in 和 not in -------------------- @@ -130,8 +130,4 @@ python 代码快。 print(is_in("hello, python", "llo")) # True print(is_in("hello, python", "lol")) # False -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_06.rst b/source/c03/c03_06.rst index a139415..503744d 100644 --- a/source/c03/c03_06.rst +++ b/source/c03/c03_06.rst @@ -1,7 +1,7 @@ 3.6 海象运算符的三种用法 ======================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png Python 版本发展非常快,如今最新的版本已经是 Pyhton 3.9,即便如此,有很多人甚至还停留在 3.6 或者 3.7,连 3.8 还没用上。 @@ -14,7 +14,7 @@ Python 版本发展非常快,如今最新的版本已经是 Pyhton 它的英文原名叫 ``Assignment Expressions``\ ,翻译过来也就是 ``赋值表达式``\ ,不过现在大家更普遍地称之为海象运算符,就是因为它长得真的太像海象了。 -|image1| +.. image:: http://image.iswbm.com/image-20200418122739417.png 第一个用法:if/else ------------------- @@ -173,9 +173,4 @@ Golang,那这里要注意,Golang 中的 ``:=`` 海象运算符,是一个新奇的特性,有不少人觉得这样这样会破坏代码的可读性。确实在一个新鲜事物刚出来时是会这样,但我相信经过时间的沉淀后,越来越多的人使用它并享受它带来的便利时,这种争议也会慢慢消失在历史的长河中。 -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/image-20200418122739417.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_07.rst b/source/c03/c03_07.rst index 10ce129..06a0909 100644 --- a/source/c03/c03_07.rst +++ b/source/c03/c03_07.rst @@ -1,7 +1,7 @@ 3.7 模块重载的五种方法 ====================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 环境准备 -------- @@ -152,8 +152,4 @@ sys.modules 来重载模块这种方法是失效的。 >>> from foo import bar >>> -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_08.rst b/source/c03/c03_08.rst index 188d26a..528ea72 100644 --- a/source/c03/c03_08.rst +++ b/source/c03/c03_08.rst @@ -1,7 +1,7 @@ 3.8 Python 转义的五种表示法 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1. 为什么要有转义? ------------------- @@ -36,12 +36,12 @@ ASCII 表中一共有 128 把八进制的 13 转成 10 进制后是 11 -|image1| +.. image:: http://image.iswbm.com/image-20201125122441089.png 对照查看 ASCII 码表,11 对应的是一个垂直定位符号,这就能解释,为什么是阶梯状的输出字符串。 -|image2| +.. image:: http://image.iswbm.com/image-20201125122651086.png 2. 转义的 5 种表示法 -------------------- @@ -84,7 +84,7 @@ ASCII 有 128 个字符,如果用 与此类似的表示法,还有如下这些 -|image3| +.. image:: http://image.iswbm.com/image-20201125213925997.png 于是,要实现 ``hello`` + 回车 + ``world`` ,就有了第三种方法 @@ -161,7 +161,7 @@ Unicode 编码其实还可以由 8 试想一下,假如你的同事,在打印日志时,使用这种 unicode 编码,然后你在定位问题的时候使用这个关键词去搜,却发现什么都搜不到?这就扑街了。 -|image4| +.. image:: http://image.iswbm.com/image-20201126090917123.png 虽然这种行为真的很 sb,但在某些人看来也许是非常牛逼的操作呢? @@ -335,12 +335,4 @@ Unicode 编码其实还可以由 8 如果本文对你有些许帮助,不如给明哥 **来个四连** ~ 比心 -|image5| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/image-20201125122441089.png -.. |image2| image:: http://image.iswbm.com/image-20201125122651086.png -.. |image3| image:: http://image.iswbm.com/image-20201125213925997.png -.. |image4| image:: http://image.iswbm.com/image-20201126090917123.png -.. |image5| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_09.rst b/source/c03/c03_09.rst index 52d0162..b4897a4 100644 --- a/source/c03/c03_09.rst +++ b/source/c03/c03_09.rst @@ -1,7 +1,7 @@ 3.9 Python 装包的八种方法 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1. 使用 easy_install -------------------- @@ -49,7 +49,7 @@ pip 是最主流的包管理方案,使用 ``pip install xxx`` 就可以从 PYP $ pip install pkg<=2.1.2 更多 pip 的使用方法,可参考我之前写过的文章,介绍得非常清楚:\ `8.8 pip -的详细使用指南 `__ +的详细使用指南 `__ 3. 使用 pipx ------------ @@ -73,8 +73,7 @@ pipx 是一个专门用于安装和管理 cli 应用程序的工具,使用它 $ pipx install pkg 更多 pipx 的使用方法,可参考我之前写过的文章,介绍得非常清楚:\ `12.4 -pipx -安装程序的使用指南 `__ +pipx 安装程序的使用指南 `__ 4. 使用 setup.py ---------------- @@ -141,8 +140,4 @@ Python 包在使用 ``setup.py`` $ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_10.rst b/source/c03/c03_10.rst index 703e627..c20c7d4 100644 --- a/source/c03/c03_10.rst +++ b/source/c03/c03_10.rst @@ -1,7 +1,7 @@ 3.10 Python装饰器的六种写法 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 装饰器本质上是一个Python函数,它可以让其他函数在不需要做任何代码变动的前提下增加额外功能,装饰器的返回值也是一个函数对象。 @@ -338,11 +338,6 @@ Python工匠:使用装饰器的小技巧) 其实例化的过程,你可以参考我这里的调试过程,加以理解。 -|image1| - -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20190512113917.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20190512113917.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_11.rst b/source/c03/c03_11.rst index a5885ba..6c49d68 100644 --- a/source/c03/c03_11.rst +++ b/source/c03/c03_11.rst @@ -1,7 +1,7 @@ 3.11 Python 读取文件的六种方式 ============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 第一种:使用 open ----------------- @@ -94,8 +94,4 @@ os 模块也自带了 open 函数,直接操作的是底层的 I/O b'hello, world' >>> os.close(fp) -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_12.rst b/source/c03/c03_12.rst index 6b67cec..f2e337b 100644 --- a/source/c03/c03_12.rst +++ b/source/c03/c03_12.rst @@ -1,7 +1,7 @@ 3.12 调用函数的九种方法 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 方法一:直接调用函数运行 ------------------------ @@ -221,8 +221,4 @@ open 来读取,最后使用 compile 函数编译运行。 p = People() caller(p) -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c04/c04_01.rst b/source/c04/c04_01.rst index 7f01caa..c8a0531 100644 --- a/source/c04/c04_01.rst +++ b/source/c04/c04_01.rst @@ -1,7 +1,7 @@ 4.1 精通上下文管理器 ==================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png ``with`` 这个关键字,对于每一学习Python的人,都不会陌生。 @@ -195,11 +195,11 @@ open)的上下文管理器。 这段代码的主逻辑是\ ``创建快照``\ ,而\ ``创建临时目录``\ ,属于前置条件,\ ``删除临时目录``\ ,是收尾工作。 -虽然代码量很少,逻辑也不复杂,但是"``创建临时目录,使用完后再删除临时目录``"这个功能,在一个项目中很多地方都需要用到,如果可以将这段逻辑处理写成一个工具函数作为一个上下文管理器,那代码的复用率也大大提高。 +虽然代码量很少,逻辑也不复杂,但是"\ ``创建临时目录,使用完后再删除临时目录``\ "这个功能,在一个项目中很多地方都需要用到,如果可以将这段逻辑处理写成一个工具函数作为一个上下文管理器,那代码的复用率也大大提高。 代码是这样的 -|image1| +.. image:: http://image.iswbm.com/20190310172800.png 总结起来,使用上下文管理器有三个好处: @@ -207,9 +207,4 @@ open)的上下文管理器。 2. 提高代码的优雅度; 3. 提高代码的可读性; -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20190310172800.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c04/c04_02.rst b/source/c04/c04_02.rst index fb9aacb..136f1ee 100644 --- a/source/c04/c04_02.rst +++ b/source/c04/c04_02.rst @@ -1,7 +1,7 @@ 4.2 深入理解描述符 ================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 学习 Python 这么久了,说起 Python 的优雅之处,能让我脱口而出的, Descriptor(描述符)特性可以排得上号。 @@ -76,7 +76,7 @@ Descriptor(描述符)特性可以排得上号。 这下程序稍微有点人工智能了,能够自己明辨是非了。 -|image1| +.. image:: http://image.iswbm.com/20190425221322.png 程序是智能了,但在\ ``__init__``\ 里有太多的判断逻辑,很影响代码的可读性。巧的是,你刚好学过 Property @@ -131,7 +131,7 @@ Property 程序还是一样的人工智能,非常好。 -|image2| +.. image:: http://image.iswbm.com/20190425221322.png 你以为你写的代码,已经非常优秀,无懈可击了。 @@ -201,7 +201,7 @@ math、chinese、english这三个属性的时候,都会经过 Score 实现的效果和前面的一样,可以对数据的合法性进行有效控制(字段类型、数值区间等) -|image3| +.. image:: http://image.iswbm.com/20190425221233.png 以上,我举了下具体的实例,从最原始的编码风格到 Property ,最后引出描述符。由浅入深,一步一步带你感受到描述符的优雅之处。 @@ -473,7 +473,7 @@ property 其实就相当于一个描述符类,而\ ``myfunc`` 在此刻变成了一个描述符。关于 ``staticmethod`` 的实现,你可以参照下面这段我自己写的代码,加以理解。 -|image4| +.. image:: http://image.iswbm.com/20190519001930.png 调用这个方法可以知道,每调用一次,它都会经过描述符类的 ``__get__`` 。 @@ -628,7 +628,7 @@ Student 引导程序逻辑进入描述符之后,不管你是获取属性,还是设置属性,都是直接作用于 instance 的。 -|image5| +.. image:: http://image.iswbm.com/20200812085823.png 这段代码,你可以仔细和前面的对比一下。 @@ -639,13 +639,4 @@ instance 的。 以上便是我对描述符的全部分享,希望能对你有所帮助。 -|image6| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20190425221322.png -.. |image2| image:: http://image.iswbm.com/20190425221322.png -.. |image3| image:: http://image.iswbm.com/20190425221233.png -.. |image4| image:: http://image.iswbm.com/20190519001930.png -.. |image5| image:: http://image.iswbm.com/20200812085823.png -.. |image6| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c04/c04_03.rst b/source/c04/c04_03.rst index a22320a..7049fdb 100644 --- a/source/c04/c04_03.rst +++ b/source/c04/c04_03.rst @@ -1,7 +1,7 @@ 4.3 神奇的元类编程 ================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1. 类是如何产生的 ----------------- @@ -369,8 +369,4 @@ ORM的一个类(User),就对应数据库中的一张表。id,name,email,passwo 元编程 `__ - `深刻理解Python中的元类 `__ -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_01.rst b/source/c05/c05_01.rst index 6df44d3..2f3d56a 100644 --- a/source/c05/c05_01.rst +++ b/source/c05/c05_01.rst @@ -1,7 +1,7 @@ 5.1 嵌套上下文管理的另类写法 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当我们要写一个嵌套的上下文管理器时,可能会这样写 @@ -38,8 +38,4 @@ with test_context('aaa'), test_context('bbb'): print('========== in main ============') -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_02.rst b/source/c05/c05_02.rst index 827de8b..f81118b 100644 --- a/source/c05/c05_02.rst +++ b/source/c05/c05_02.rst @@ -1,7 +1,7 @@ 5.2 将嵌套 for 循环写成单行 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 我们经常会写如下这种嵌套的 for 循环代码 @@ -44,8 +44,4 @@ 14 15 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_03.rst b/source/c05/c05_03.rst index 33b9c9f..fbc11c8 100644 --- a/source/c05/c05_03.rst +++ b/source/c05/c05_03.rst @@ -1,7 +1,7 @@ 5.3 单行实现 for 死循环如何写? =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 如果让你在不借助 while ,只使用 for 来写一个死循环? @@ -39,8 +39,4 @@ 由于int() 永远返回0,永远返回不了1,所以这个 for 循环会没有终点。一直运行下去。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_04.rst b/source/c05/c05_04.rst index 55e8d76..006c3ab 100644 --- a/source/c05/c05_04.rst +++ b/source/c05/c05_04.rst @@ -1,7 +1,7 @@ 5.4 如何关闭异常自动关联上下文? ================================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你在处理异常时,由于处理不当或者其他问题,再次抛出另一个异常时,往外抛出的异常也会携带原始的异常信息。 @@ -88,8 +88,4 @@ RuntimeError: Something bad happened (PythonCodingTime) -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_05.rst b/source/c05/c05_05.rst index c501fac..613b9d8 100644 --- a/source/c05/c05_05.rst +++ b/source/c05/c05_05.rst @@ -1,7 +1,7 @@ 5.5 自带的缓存机制不用白不用 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 缓存是一种将定量数据加以保存,以备迎合后续获取需求的处理方式,旨在加快数据获取的速度。 @@ -47,8 +47,4 @@ calculating: 2 + 3 5 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_06.rst b/source/c05/c05_06.rst index 7f862eb..589942c 100644 --- a/source/c05/c05_06.rst +++ b/source/c05/c05_06.rst @@ -1,7 +1,7 @@ 5.6 如何流式读取数G超大文件 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 使用 with...open... 可以从一个文件中读取数据,这是所有 Python 开发者都非常熟悉的操作。 @@ -68,8 +68,4 @@ while chunk := fp.read(block_size): yield chunk -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_07.rst b/source/c05/c05_07.rst index cfd3da8..c8633a9 100644 --- a/source/c05/c05_07.rst +++ b/source/c05/c05_07.rst @@ -1,7 +1,7 @@ 5.7 实现类似 defer 的延迟调用 ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在 Golang 中有一种延迟调用的机制,关键字是 defer,例如下面的示例 @@ -50,8 +50,4 @@ A B -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_08.rst b/source/c05/c05_08.rst index 5884c95..71bb7cd 100644 --- a/source/c05/c05_08.rst +++ b/source/c05/c05_08.rst @@ -1,7 +1,7 @@ 5.8 如何快速计算函数运行时间 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 计算一个函数的运行时间,你可能会这样子做 @@ -43,8 +43,4 @@ timeit ​ 使用它,只用一行代码即可 2 10.020059824 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_09.rst b/source/c05/c05_09.rst index d333815..28bb9c7 100644 --- a/source/c05/c05_09.rst +++ b/source/c05/c05_09.rst @@ -1,7 +1,7 @@ 5.9 重定向标准输出到日志 ======================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 假设你有一个脚本,会执行一些任务,比如说集群健康情况的检查。 @@ -39,8 +39,4 @@ with close_stdout(): you_task() -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_10.rst b/source/c05/c05_10.rst index d068b86..1fcd6f2 100644 --- a/source/c05/c05_10.rst +++ b/source/c05/c05_10.rst @@ -1,7 +1,7 @@ 5.10 快速定位错误进入调试模式 ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你在写一个程序时,最初的程序一定遇到不少零零散散的错误,这时候就免不了调试一波。 @@ -23,18 +23,12 @@ pdb 的代码。 方法很简单,只需要你在执行脚本时,加入 ``-i`` 参考 -|image1| +.. image:: http://image.iswbm.com/20200615235900.png 如果你的程序没有任何问题,加上 ``-i`` 后又会有什么不一样呢? 从下图可以看出,程序执行完成后会自动进入 console 交互模式。 -|image2| - -|image3| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200615235900.png -.. |image2| image:: http://image.iswbm.com/image-20200616000039009.png -.. |image3| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/image-20200616000039009.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_11.rst b/source/c05/c05_11.rst index 6cea8c1..bbc500b 100644 --- a/source/c05/c05_11.rst +++ b/source/c05/c05_11.rst @@ -1,7 +1,7 @@ 5.11 在程序退出前执行代码的技巧 =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 使用 atexit 这个内置模块,可以很方便地注册退出函数。 @@ -9,7 +9,7 @@ 示例如下 -|image1| +.. image:: http://image.iswbm.com/20200510112133.png 如果\ ``clean()``\ 函数有参数,那么你可以不用装饰器,而是直接调用\ ``atexit.register(clean_1, 参数1, 参数2, 参数3='xxx')``\ 。 @@ -22,9 +22,4 @@ - 如果发生了严重的 Python 内部错误,你注册的函数无法正常执行。 - 如果你手动调用了\ ``os._exit()``\ ,你注册的函数无法正常执行。 -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200510112133.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_12.rst b/source/c05/c05_12.rst index 62502ac..e05e8d5 100644 --- a/source/c05/c05_12.rst +++ b/source/c05/c05_12.rst @@ -1,7 +1,7 @@ 5.12 逗号也有它的独特用法 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 逗号,虽然是个很不起眼的符号,但在 Python 中也有他的用武之地。 @@ -44,8 +44,4 @@ print 的取消换行 0 1 2 [root@localhost ~]# -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_13.rst b/source/c05/c05_13.rst index 0362cff..f400762 100644 --- a/source/c05/c05_13.rst +++ b/source/c05/c05_13.rst @@ -1,7 +1,7 @@ 5.13 如何在运行状态查看源代码? =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 查看函数的源代码,我们通常会使用 IDE 来完成。 @@ -36,8 +36,4 @@ def add(x, y): return x + y -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_14.rst b/source/c05/c05_14.rst index 5cc5304..48036e5 100644 --- a/source/c05/c05_14.rst +++ b/source/c05/c05_14.rst @@ -1,7 +1,7 @@ 5.14 单分派泛函数如何写? ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 泛型,如果你尝过java,应该对他不陌生吧。但你可能不知道在 Python 中(3.4+ ),也可以实现 简单的泛型函数。 @@ -166,8 +166,4 @@ ('apple', 'huawei', 'vivo', 'oppo') 【错误】:参数类型不同,无法拼接!! -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_15.rst b/source/c05/c05_15.rst index 4c97bc3..3aacf37 100644 --- a/source/c05/c05_15.rst +++ b/source/c05/c05_15.rst @@ -1,7 +1,7 @@ 5.15 让我爱不释手的用户环境 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你在机器上并没有 root 权限时,如何安装 Python 的第三方包呢? @@ -41,8 +41,4 @@ [root@localhost ~]$ pip list | grep requests [root@localhost ~]$ -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_16.rst b/source/c05/c05_16.rst index ddfeee1..52fd8ad 100644 --- a/source/c05/c05_16.rst +++ b/source/c05/c05_16.rst @@ -1,7 +1,7 @@ 5.16 字符串的分割技巧 ===================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当我们对字符串进行分割时,且分割符是 ``\n``\ ,有可能会出现这样一个窘境: @@ -75,8 +75,4 @@ 因此在多个换行符的情况下,请务必使用 split 方法。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_17.rst b/source/c05/c05_17.rst index 508dcb9..b24dcde 100644 --- a/source/c05/c05_17.rst +++ b/source/c05/c05_17.rst @@ -1,7 +1,7 @@ 5.17 反转字符串/列表最优雅的方式 ================================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 反转序列并不难,但是如何做到最优雅呢? @@ -46,8 +46,4 @@ >>> ml[::-1] [3, 2, 1] -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_18.rst b/source/c05/c05_18.rst index 7229359..72d6ab9 100644 --- a/source/c05/c05_18.rst +++ b/source/c05/c05_18.rst @@ -1,7 +1,7 @@ 5.18 如何将 print 内容输出到文件 ================================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png Python 3 中的 print 作为一个函数,由于可以接收更多的参数,所以功能变为更加强大。 @@ -18,8 +18,4 @@ Python 3 中的 print $ cat test.log hello, python -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_19.rst b/source/c05/c05_19.rst index bba03f6..03ad9cc 100644 --- a/source/c05/c05_19.rst +++ b/source/c05/c05_19.rst @@ -1,7 +1,7 @@ 5.19 改变默认递归次数限制 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 上面才提到递归,大家都知道使用递归是有风险的,递归深度过深容易导致堆栈的溢出。如果你这字符串太长啦,使用递归方式反转,就会出现问题。 @@ -21,8 +21,4 @@ >>> sys.getrecursionlimit() 2000 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_20.rst b/source/c05/c05_20.rst index 91667ba..f9191c4 100644 --- a/source/c05/c05_20.rst +++ b/source/c05/c05_20.rst @@ -1,7 +1,7 @@ 5.20 让你晕头转向的 else 用法 ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png if else 用法可以说是最基础的语法表达式之一,但是今天不是讲这个的。 @@ -67,8 +67,4 @@ break,还是没有break? 总结一下,for else 和 try else 相同,只要代码正常走下去不被 break,不抛出异常,就可以走else。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_21.rst b/source/c05/c05_21.rst index 74da09a..2caf116 100644 --- a/source/c05/c05_21.rst +++ b/source/c05/c05_21.rst @@ -1,7 +1,7 @@ 5.21 字典访问不存在的key时不再报错 ================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当一个字典里没有某个 key 时,此时你访问他是会报 KeyError 的。 @@ -64,8 +64,4 @@ defaultdict 接收一个工厂方法,工厂方法返回的对象就是字典 >>> info["msg"] 'default value' -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_22.rst b/source/c05/c05_22.rst index a006dd0..94968b5 100644 --- a/source/c05/c05_22.rst +++ b/source/c05/c05_22.rst @@ -1,7 +1,7 @@ 5.22 如何实现函数的连续调用? ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 现在我想写一个函数可以实现把所有的数进行求和,并且可以达到反复调用的目的。 @@ -54,8 +54,4 @@ 27 >>> -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_23.rst b/source/c05/c05_23.rst index 113631b..50998c2 100644 --- a/source/c05/c05_23.rst +++ b/source/c05/c05_23.rst @@ -1,7 +1,7 @@ 5.23 如何实现字典的多级排序 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在一个列表中,每个元素都是一个字典,里面的每个字典结构都是一样的。 @@ -46,8 +46,4 @@ >>> students [{'age': 17, 'score': 80, 'name': 'Julia'}, {'age': 16, 'score': 80, 'name': 'Tom'}, {'age': 17, 'score': 89, 'name': 'Jack'}] -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_24.rst b/source/c05/c05_24.rst index adb47c3..6cb6c2d 100644 --- a/source/c05/c05_24.rst +++ b/source/c05/c05_24.rst @@ -1,7 +1,7 @@ 5.24 对齐字符串的两种方法 ========================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 第一种:使用 format ------------------- @@ -141,8 +141,4 @@ 09 081 0729 10 100 1000 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_25.rst b/source/c05/c05_25.rst index 22f6fae..5fc0fa9 100644 --- a/source/c05/c05_25.rst +++ b/source/c05/c05_25.rst @@ -1,7 +1,7 @@ 5.25 将位置参数变成关键字参数 ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在 Python 中,参数的种类,大概可以分为四种: @@ -33,8 +33,4 @@ 2 3 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_26.rst b/source/c05/c05_26.rst index 30984e6..44738a1 100644 --- a/source/c05/c05_26.rst +++ b/source/c05/c05_26.rst @@ -1,7 +1,7 @@ 5.26 如何获取一个函数设定的参数 =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在 Python 中有一个叫 inspect 的库,非常的好用,利用它可以获取一些数据,这在写一些框架时非常有用。 @@ -39,8 +39,4 @@ raise TypeError(msg) from None TypeError: missing a required argument: 'age' -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_27.rst b/source/c05/c05_27.rst index 3a4e50d..0fe2894 100644 --- a/source/c05/c05_27.rst +++ b/source/c05/c05_27.rst @@ -1,7 +1,7 @@ 5.27 如何进行版本的比较 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 使用 distutils -------------- @@ -38,8 +38,4 @@ >>> version.parse("1.3.a4") < version.parse("10.1.2") True -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_28.rst b/source/c05/c05_28.rst index 1814d27..772b1c2 100644 --- a/source/c05/c05_28.rst +++ b/source/c05/c05_28.rst @@ -22,28 +22,23 @@ 在不进行任何设置的情况下,警告会直接打印在终端上。 -|image0| +.. image:: http://image.iswbm.com/20210313143425.png 3. 捕获警告方法一 ----------------- 在 warnings 中有一系列的过滤器。 -+---------------+--------------------------------------------------------+ -| 值 | 处置 | -+===============+========================================================+ -| ``"default"`` | 为发出警告的每个位置(模块+行号)打印第一个匹配警告 | -+---------------+--------------------------------------------------------+ -| ``"error"`` | 将匹配警告转换为异常 | -+---------------+--------------------------------------------------------+ -| ``"ignore"`` | 从不打印匹配的警告 | -+---------------+--------------------------------------------------------+ -| ``"always"`` | 总是打印匹配的警告 | -+---------------+--------------------------------------------------------+ -| ``"module"`` | 为发出警告的每个模块打印第一次匹配警告(无论行号如何) | -+---------------+--------------------------------------------------------+ -| ``"once"`` | 无论位置如何,仅打印第一次出现的匹配警告 | -+---------------+--------------------------------------------------------+ +============= ====================================================== +值 处置 +============= ====================================================== +``"default"`` 为发出警告的每个位置(模块+行号)打印第一个匹配警告 +``"error"`` 将匹配警告转换为异常 +``"ignore"`` 从不打印匹配的警告 +``"always"`` 总是打印匹配的警告 +``"module"`` 为发出警告的每个模块打印第一次匹配警告(无论行号如何) +``"once"`` 无论位置如何,仅打印第一次出现的匹配警告 +============= ====================================================== 当你指定为 error 的时候,就会将匹配警告转换为异常。 @@ -61,7 +56,7 @@ 运行后,效果如下 -|image1| +.. image:: http://image.iswbm.com/20210313144501.png 4. 捕获警告方法二 ----------------- @@ -107,9 +102,4 @@ 运行后,效果如下 -|image2| - -.. |image0| image:: http://image.iswbm.com/20210313143425.png -.. |image1| image:: http://image.iswbm.com/20210313144501.png -.. |image2| image:: http://image.iswbm.com/20210313144751.png - +.. image:: http://image.iswbm.com/20210313144751.png diff --git a/source/c05/c05_29.rst b/source/c05/c05_29.rst index 0d6aa21..29e8c0b 100644 --- a/source/c05/c05_29.rst +++ b/source/c05/c05_29.rst @@ -1,7 +1,7 @@ 5.29 如何禁止对象深拷贝? ======================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当你使用 copy 模块的 deepcopy 拷贝一个对象后,会创建出来一个全新的的对象。 @@ -47,8 +47,4 @@ Python 的魔法方法了。>>> id(new_obj) 140151569169808 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_30.rst b/source/c05/c05_30.rst index 534c79f..08e29e6 100644 --- a/source/c05/c05_30.rst +++ b/source/c05/c05_30.rst @@ -1,7 +1,7 @@ 5.30 如何将变量名和变量值转为字典? =================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 千言万语,不如上示例演示下效果 @@ -46,8 +46,4 @@ 附上 :\ `inspect 学习文档 `__ -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_31.rst b/source/c05/c05_31.rst index 2e872d3..2da60be 100644 --- a/source/c05/c05_31.rst +++ b/source/c05/c05_31.rst @@ -1,7 +1,7 @@ 5.31 替换实例方法的最佳实践 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 思路一:简单替换 ---------------- @@ -58,7 +58,7 @@ method ,你可以把替换前后的 speak 打印出来 有 Python 2 使用经验的朋友,可以会知道类实例的方法,都有 ``im_func`` 和 ``im_class`` 属性,分别指向了该方法的函数和类。 -|image1| +.. image:: http://image.iswbm.com/20210328111610.png 很抱歉的是,这些在 Python3 中全都取消了,意味你无法再使用 ``im_func`` 和 ``im_class`` 。 @@ -69,19 +69,19 @@ method ,你可以把替换前后的 speak 打印出来 因为在 Python2 中不推荐普通用户对类实例的方法进行替换,所以 Python 给类实例的方法赋予了只读属性 -|image2| +.. image:: http://image.iswbm.com/20210328111904.png 思路三:非常危险的字节码替换 ---------------------------- 表层不行,但这个方法在字节码层面却是可行的 -|image3| +.. image:: http://image.iswbm.com/20210328112231.png 这种方法,非常的粗暴且危险,他会直接影响到使用 People 的所有实例的 speak 方法,因此这种方法千万不要使用。 -|image4| +.. image:: http://image.iswbm.com/20210328112501.png 思路四:利用 types 绑定方法 --------------------------- @@ -109,12 +109,4 @@ method ,你可以把替换前后的 speak 打印出来 这种方法,最为安全,不会影响其他实例。并且 Python 2 和 Python 3 都适用,是官方推荐的一种做法。 -|image5| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20210328111610.png -.. |image2| image:: http://image.iswbm.com/20210328111904.png -.. |image3| image:: http://image.iswbm.com/20210328112231.png -.. |image4| image:: http://image.iswbm.com/20210328112501.png -.. |image5| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_32.rst b/source/c05/c05_32.rst index 46c3ab0..521d63e 100644 --- a/source/c05/c05_32.rst +++ b/source/c05/c05_32.rst @@ -1,7 +1,7 @@ 5.32 如何动态创建函数? ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在下面的代码中,每一次 for 循环都会创建一个返回特定字符串的函数。 @@ -26,8 +26,4 @@ world python -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_01.rst b/source/c06/c06_01.rst index 77aa6b4..a68e842 100644 --- a/source/c06/c06_01.rst +++ b/source/c06/c06_01.rst @@ -1,7 +1,7 @@ 6.1 不要直接调用类的私有方法 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 大家都知道,类中可供直接调用的方法,只有公有方法(protected类型的方法也可以,但是不建议)。也就是说,类的私有方法是无法直接调用的。 @@ -40,8 +40,4 @@ ins._Kls__private() ins.call_private() -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_02.rst b/source/c06/c06_02.rst index ac11fc3..0ab9ca1 100644 --- a/source/c06/c06_02.rst +++ b/source/c06/c06_02.rst @@ -1,7 +1,7 @@ 6.2 默认参数最好不为可变对象 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 函数的参数分三种 @@ -43,11 +43,6 @@ Python 中的 def 的时候,会先生成这个可变对象的内存地址,然后将这个默认参数 item_list 会与这个内存地址绑定。在后面的函数调用中,如果调用方指定了新的默认值,就会将原来的默认值覆盖。如果调用方没有指定新的默认值,那就会使用原来的默认值。 -|image1| - -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20190511165650.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20190511165650.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_03.rst b/source/c06/c06_03.rst index 70a0867..73aa3bf 100644 --- a/source/c06/c06_03.rst +++ b/source/c06/c06_03.rst @@ -1,7 +1,7 @@ 6.3 增量赋值的性能更好 ====================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 诸如 ``+=`` 和 ``*=`` 这些运算符,叫做 增量赋值运算符。 @@ -26,8 +26,4 @@ a+b,前者是直接在原列表上进行扩展,而后者是先从原列表中 所以在能使用增量赋值的时候尽量使用它。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_04.rst b/source/c06/c06_04.rst index 5191ea1..4b99dcd 100644 --- a/source/c06/c06_04.rst +++ b/source/c06/c06_04.rst @@ -1,7 +1,7 @@ 6.4 别再使用 pprint 打印了 ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 1. 吐槽问题 ----------- @@ -47,7 +47,7 @@ pprint 你应该很熟悉了吧? 好像有点效果,真的是 "神器"呀。 但是你告诉我, -**:raw-latex:`\xe`4:raw-latex:`\xbd`:raw-latex:`\xa`0:raw-latex:`\xe`7:raw-latex:`\x`9a** +**:raw-latex:`\xe4`:raw-latex:`\xbd`:raw-latex:`\xa0`:raw-latex:`\xe7`:raw-latex:`\x`9a** 这些是什么玩意?本来想提高可读性的,现在变成完全不可读了。 好在我懂点 Python 2 的编码,知道 Python 2 @@ -162,7 +162,7 @@ Python,本来我可以选择不用的,因为有更好的替代方案(\ ** 输出如下,已经解决了中文的显示问题: -|image1| +.. image:: http://image.iswbm.com/20200507171451.png 打印双引号 ~~~~~~~~~~ @@ -269,7 +269,7 @@ stream,也就是标准输出。 就像下面这样。 -|image2| +.. image:: http://image.iswbm.com/20200507174459.png 知道了问题所在,再修改下代码 @@ -294,7 +294,7 @@ stream,也就是标准输出。 终于成功了,太不容易了吧。 -|image3| +.. image:: http://image.iswbm.com/20200507174802.png 3. 何必折腾 ----------- @@ -379,11 +379,4 @@ json.dumps 的关键参数有两个: 2. 若真要使用,且有和我一样的改造需求,可以参考我的实现 3. Python 2 中的 print 语句后居然可以加 逗号 -|image4| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200507171451.png -.. |image2| image:: http://image.iswbm.com/20200507174459.png -.. |image3| image:: http://image.iswbm.com/20200507174802.png -.. |image4| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_05.rst b/source/c06/c06_05.rst index 25875c4..d42a33b 100644 --- a/source/c06/c06_05.rst +++ b/source/c06/c06_05.rst @@ -1,7 +1,7 @@ 6.5 变量名与保留关键字冲突怎么办? ================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 所有的编程语言都有一些保留关键字,这是代码得以编译/解释的基础。 @@ -65,7 +65,7 @@ Python 的关键字,可以通过 keyword 这个模块列出来,一共有 33 建议当你想使用的变量名被关键字所占用时,可以使用 ``变量_`` 这样在变量后面加一个单下划线的形式来命名,这种后缀一下划线的方式优先于缩写或拼写错误。 -|image1| +.. image:: http://image.iswbm.com/20200823203106.png 有了 PEP8 做为指导,我们可以这样子写了 @@ -73,9 +73,4 @@ Python 的关键字,可以通过 keyword 这个模块列出来,一共有 33 >>> try_ = True -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200823203106.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_06.rst b/source/c06/c06_06.rst index 4389c58..d055432 100644 --- a/source/c06/c06_06.rst +++ b/source/c06/c06_06.rst @@ -1,7 +1,7 @@ 6.6 不想让子类继承的变量名该怎么写? ==================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 先来看下面这段代码 @@ -47,11 +47,6 @@ Parent 验证过程如下: -|image1| - -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200823205210.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png +.. image:: http://image.iswbm.com/20200823205210.png +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_07.rst b/source/c06/c06_07.rst index d5be221..1d2094b 100644 --- a/source/c06/c06_07.rst +++ b/source/c06/c06_07.rst @@ -1,7 +1,7 @@ 6.7 利用 any 代替 for 循环 ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在某些场景下,我们需要判断是否满足某一组集合中任意一个条件 @@ -34,8 +34,4 @@ 只要有一个不满足条件,all 函数的结果就会立刻返回 False -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_08.rst b/source/c06/c06_08.rst index ac69ff1..1bc4dc5 100644 --- a/source/c06/c06_08.rst +++ b/source/c06/c06_08.rst @@ -1,7 +1,7 @@ 6.8 不同条件分支里应减少重合度 ============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 如下是一个简单的条件语句模型 @@ -39,8 +39,4 @@ else: process_international_payment(payment) -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_09.rst b/source/c06/c06_09.rst index 08455b4..b31cf6b 100644 --- a/source/c06/c06_09.rst +++ b/source/c06/c06_09.rst @@ -1,7 +1,7 @@ 6.9 如无必要,勿增实体噢 ======================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 删除没必要的调用\ ``keys()`` ---------------------------- @@ -67,8 +67,4 @@ 这样可以缩短代码并删除不必要的变量,从而减轻了读取函数的负担。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_10.rst b/source/c06/c06_10.rst index e8be3b4..75fde65 100644 --- a/source/c06/c06_10.rst +++ b/source/c06/c06_10.rst @@ -1,7 +1,7 @@ 6.10 保持代码的简洁与可诗性 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 将条件简化为return语句 ---------------------- @@ -22,8 +22,4 @@ def function(): return isinstance(a, b) or issubclass(b, a) -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_11.rst b/source/c06/c06_11.rst index b93ac41..9e56739 100644 --- a/source/c06/c06_11.rst +++ b/source/c06/c06_11.rst @@ -1,7 +1,7 @@ 6.11 给模块的私有属性上保险 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 保护对象 -------- @@ -57,8 +57,4 @@ 甚至是,使用\ ``import tools``\ 也可以轻易突破保护限制。所以可见,"保护属性"是一种简单的隐藏机制,只有在\ ``from tools import *``\ 时,由解释器提供简单的保护,但是可以轻易突破。这种保护更多地依赖程序员的共识:不访问、修改"保护属性"。除此之外,有没有更安全的保护机制呢?有,就是下一部分讨论的私有变量。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_12.rst b/source/c06/c06_12.rst index 3c81868..03d974d 100644 --- a/source/c06/c06_12.rst +++ b/source/c06/c06_12.rst @@ -1,7 +1,7 @@ 6.12 变量不能与保留关键字重名 ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在 Python 中有很多的保留关键字,这些关键字的使用,不需要我们定义,也不需要我们导入,只要你进入到了 @@ -30,8 +30,4 @@ class,这个有类别的意思,可能你也想使用它来作为变量名, def tag(name,*content,class_): pass -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_01.rst b/source/c07/c07_01.rst index b75c0f2..becf148 100644 --- a/source/c07/c07_01.rst +++ b/source/c07/c07_01.rst @@ -1,7 +1,7 @@ 7.1 远程登陆服务器的最佳利器 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在使用 Python 写一些脚本的时候,在某些情况下,我们需要频繁登陆远程服务去执行一次命令,并返回一些结果。 @@ -59,7 +59,7 @@ os.popen,os.system,commands,subprocess 等一些命令执行库来间接 为了解决这几个问题,我搜索了全网关于 Python ssh 的文章,没有看到有完整介绍这方面的技巧的。 -|image1| +.. image:: http://image.iswbm.com/20200512125643.png 为此,我就翻阅了一个很火的 Github 项目: awesome-python-cn (https://github.com/BingmingWong/awesome-python-cn)。 @@ -136,7 +136,7 @@ os.popen,os.system,commands,subprocess 等一些命令执行库来间接 2017 年就已经存在这个问题了,到现在 2020 年了还没有修复,看来使用 ``sh.ssh`` 的人并不多,于是我又"追问"了下,期望能得到回复。 -|image2| +.. image:: http://image.iswbm.com/20200228085749.png 以上这个问题,只有在需要输入密码才会出现,如果设置了机器互信是没有问题的。 @@ -173,11 +173,11 @@ top 命令看到已连接的终端的变化,会先 ``+1`` 再 你得使用它的兄弟库 - ``pbs`` ,然后我又去 pypi 看了一眼 `pbs `__\ ,已经 "年久失修",没人维护了。 -|image3| +.. image:: http://image.iswbm.com/20200228093627.png 至此,我离 "卒",就差最后一根稻草了。 -|image4| +.. image:: http://image.iswbm.com/20200512125643.png 3. 使用 paramiko ---------------- @@ -340,7 +340,7 @@ Windows,这里就有一件好事,一件坏事了。 坏事就是:你需要做很多复杂的准备,你可 google 解决,但是我建议你直接放弃,坑太深了。 -|image5| +.. image:: http://image.iswbm.com/20200228111654.png 注意事项 ~~~~~~~~ @@ -389,13 +389,4 @@ Windows,这里就有一件好事,一件坏事了。 模块是运维人员必学模块之一,如果你恰好需要在 Python 代码中实现 ssh 到远程服务器去获取一些信息,那么我把 Paramiko 推荐给你。 -|image6| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200512125643.png -.. |image2| image:: http://image.iswbm.com/20200228085749.png -.. |image3| image:: http://image.iswbm.com/20200228093627.png -.. |image4| image:: http://image.iswbm.com/20200512125643.png -.. |image5| image:: http://image.iswbm.com/20200228111654.png -.. |image6| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_02.rst b/source/c07/c07_02.rst index 769bee0..ef29dff 100644 --- a/source/c07/c07_02.rst +++ b/source/c07/c07_02.rst @@ -1,14 +1,14 @@ 7.2 代码 BUG 变得酷炫的利器 =========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 当我们写的一个脚本或程序发生各种不可预知的异常时,如果我们没有进行捕获处理的时候,通常都会致使程序崩溃退出,并且会在终端打印出一堆 **密密麻麻** 的 traceback 堆栈信息来告诉我们,是哪个地方出了问题。 就像这样子,天呐,密集恐惧症要犯了都 -|image1| +.. image:: http://image.iswbm.com/image-20200307210853246.png 上面这段 traceback @@ -47,18 +47,18 @@ 随便写一个没有使用 pretty-errors ,并且报错了的程序,是这样子的。 -|image2| +.. image:: http://image.iswbm.com/image-20200307212823345.png 而使用了 pretty_errors 后,报错信息被美化成这样了。 -|image3| +.. image:: http://image.iswbm.com/image-20200307213534278.png 是不是感觉清楚了不少,那种密密麻麻带来的焦虑感是不是都消失了呢? 当然这段代码少,你可能还没感受到,那就来看下 该项目在 Github上的一张效果对比图吧 -|image4| +.. image:: https://warehouse-camo.cmh1.psfhosted.org/31399c5a034c3989b9e99b35249e8f2f0d40e102/68747470733a2f2f692e696d6775722e636f6d2f306a7045716f622e706e67 3. 配置全局可用 --------------- @@ -81,23 +81,23 @@ traceback 输出都自动美化。 $ python3 -m pretty_errors -|image5| +.. image:: http://image.iswbm.com/image-20200307214742135.png 配置完成后,你再运行任何脚本,traceback 都会自动美化了。 不仅是在我的 iTerm 终端下 -|image6| +.. image:: http://image.iswbm.com/image-20200307213534278.png 在 PyCharm 中也会 -|image7| +.. image:: http://image.iswbm.com/image-20200307215530270.png 唯一的缺点就是,原先在 PyCharm 中的 traceback 可以直接点击 ``文件路径`` 直接跳转到对应错误文件代码行,而你如果是在 VSCode 可以使用 下面自定义配置的方案解决这个问题(下面会讲到,参数是:\ ``display_link``\ )。 -|image8| +.. image:: http://image.iswbm.com/image-20200307215834623.png 因此,有些情况下,你并不想设置 ``pretty_errors`` 全局可用。 @@ -105,7 +105,7 @@ traceback 输出都自动美化。 只需要再次输入 ``python -m pretty_errors``\ ,选择 ``C`` 即可清除。 -|image9| +.. image:: http://image.iswbm.com/image-20200307214600749.png 4. 单文件中使用 --------------- @@ -179,7 +179,7 @@ traceback 输出都自动美化。 在你像上面这样使用 ``pretty_errrs.configure`` 进行配置时,抛出的异常信息就变成这样了。 -|image10| +.. image:: http://image.iswbm.com/image-20200308121949011.png 当然了,\ ``pretty_errors.configure()`` 还可以接收很多的参数,你可以根据你自己的需要进行配置。 @@ -212,18 +212,24 @@ traceback 输出都自动美化。 其中,\ ``_BACKGROUND`` 用于设置背景色,举个例子如下。 -|image11| +.. image:: http://image.iswbm.com/image-20200308125431779.png 5.2 设置显示内容 ~~~~~~~~~~~~~~~~ - ``line_number_first`` 启用后,将首先显示行号,而不是文件名。 + - ``lines_before`` : 显示发生异常处的前几行代码 + - ``lines_after``\ : 显示发生异常处的后几行代码 + - ``display_link``\ :启用后,将在错误位置下方写入链接,VScode将允许您单击该链接。 + - ``separator_character``\ :用于创建标题行的字符。默认情况下使用连字符。如果设置为 ``''`` 或者 ``None`` ,标题将被禁用。 + - ``display_timestamp``\ :启用时,时间戳将写入回溯头中。 + - ``display_locals`` 启用后,将显示在顶部堆栈框架代码中的局部变量及其值。 @@ -268,19 +274,4 @@ PEP8 规范一样,没有它是可以,但是有了它会更好一样。对于某些想自定义错误输出场景的人,\ ``pretty_errors`` 会是一个不错的解决方案,明哥把它推荐给你。 -|image12| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/image-20200307210853246.png -.. |image2| image:: http://image.iswbm.com/image-20200307212823345.png -.. |image3| image:: http://image.iswbm.com/image-20200307213534278.png -.. |image4| image:: https://warehouse-camo.cmh1.psfhosted.org/31399c5a034c3989b9e99b35249e8f2f0d40e102/68747470733a2f2f692e696d6775722e636f6d2f306a7045716f622e706e67 -.. |image5| image:: http://image.iswbm.com/image-20200307214742135.png -.. |image6| image:: http://image.iswbm.com/image-20200307213534278.png -.. |image7| image:: http://image.iswbm.com/image-20200307215530270.png -.. |image8| image:: http://image.iswbm.com/image-20200307215834623.png -.. |image9| image:: http://image.iswbm.com/image-20200307214600749.png -.. |image10| image:: http://image.iswbm.com/image-20200308121949011.png -.. |image11| image:: http://image.iswbm.com/image-20200308125431779.png -.. |image12| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_03.rst b/source/c07/c07_03.rst index 62eef2b..eca9cb7 100644 --- a/source/c07/c07_03.rst +++ b/source/c07/c07_03.rst @@ -1,7 +1,7 @@ 7.3 少有人知的 Python "重试机制" ================================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 为了避免由于一些网络或其他不可控因素,而引起的功能性问题。比如在发送请求时,会因为网络不稳定,往往会有请求超时的问题。 @@ -220,8 +220,4 @@ RetryError,而不是最根本的原因。 执行回调函数 False -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_04.rst b/source/c07/c07_04.rst index 157e501..50899de 100644 --- a/source/c07/c07_04.rst +++ b/source/c07/c07_04.rst @@ -1,7 +1,7 @@ 7.4 规整字符串提取数据的神器 ============================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 从一段指定的字符串中,取得期望的数据,正常人都会想到正则表达式吧? @@ -33,7 +33,7 @@ in_port 对应的 n_bytes、n_packets 的值 。 我来给你展示一下,我是怎么做的? -|image1| +.. image:: http://image.iswbm.com/image-20200903214325849.png 可以看到,我使用了一个叫做 parse 的第三方包,是需要自行安装的 @@ -144,8 +144,8 @@ parse 的结果只有两种: 更多类型请参考官方文档: +---+-----------------------------------------------------------+-------+ -| T | Characters Matched | Outpu | -| y | | t | +| T | Characters Matched | O | +| y | | utput | | p | | | | e | | | +===+===========================================================+=======+ @@ -169,8 +169,8 @@ parse 的结果只有两种: +---+-----------------------------------------------------------+-------+ | f | Fixed-point numbers | float | +---+-----------------------------------------------------------+-------+ -| F | Decimal numbers | Decim | -| | | al | +| F | Decimal numbers | De | +| | | cimal | +---+-----------------------------------------------------------+-------+ | e | Floating-point numbers with exponent e.g. 1.1e-10, NAN | float | | | (all case insensitive) | | @@ -183,26 +183,26 @@ parse 的结果只有两种: +---+-----------------------------------------------------------+-------+ | x | Hexadecimal numbers (lower and upper case) | int | +---+-----------------------------------------------------------+-------+ -| t | ISO 8601 format date/time e.g. 1972年01月20日T10:21:36Z ("T" | datet | -| i | and "Z" optional) | ime | +| t | ISO 8601 format date/time e.g. 1972年01月20日T10:21:36Z ("T" | dat | +| i | and "Z" optional) | etime | +---+-----------------------------------------------------------+-------+ -| t | RFC2822 e-mail format date/time e.g. 1972年1月20日 | datet | -| e | 10:21:36 +1000 | ime | +| t | RFC2822 e-mail format date/time e.g. 1972年1月20日 | dat | +| e | 10:21:36 +1000 | etime | +---+-----------------------------------------------------------+-------+ -| t | Global (day/month) format date/time e.g. 20/1/1972 | datet | -| g | 10:21:36 AM +1:00 | ime | +| t | Global (day/month) format date/time e.g. 20/1/1972 | dat | +| g | 10:21:36 AM +1:00 | etime | +---+-----------------------------------------------------------+-------+ -| t | US (month/day) format date/time e.g. 1/20/1972 10:21:36 | datet | -| a | PM +10:30 | ime | +| t | US (month/day) format date/time e.g. 1/20/1972 10:21:36 | dat | +| a | PM +10:30 | etime | +---+-----------------------------------------------------------+-------+ -| t | ctime() format date/time e.g. Sun Sep 16 01:03:52 1973 | datet | -| c | | ime | +| t | ctime() format date/time e.g. Sun Sep 16 01:03:52 1973 | dat | +| c | | etime | +---+-----------------------------------------------------------+-------+ -| t | HTTP log format date/time e.g. 21/Nov/2011:00:07:11 +0000 | datet | -| h | | ime | +| t | HTTP log format date/time e.g. 21/Nov/2011:00:07:11 +0000 | dat | +| h | | etime | +---+-----------------------------------------------------------+-------+ -| t | Linux system log format date/time e.g. Nov 9 03:37:44 | datet | -| s | | ime | +| t | Linux system log format date/time e.g. Nov 9 03:37:44 | dat | +| s | | etime | +---+-----------------------------------------------------------+-------+ | t | Time e.g. 10:21:36 PM -5:30 | time | | t | | | @@ -356,9 +356,4 @@ parse 库在字符串解析处理场景中提供的便利,肉眼可见,上 在一些简单的场景中,使用 parse 可比使用 re 去写正则开发效率不知道高几个 level,用它写出来的代码富有美感,可读性高,后期维护起代码来一点压力也没有,推荐你使用。 -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/image-20200903214325849.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_05.rst b/source/c07/c07_05.rst index 037c03f..55bba72 100644 --- a/source/c07/c07_05.rst +++ b/source/c07/c07_05.rst @@ -1,7 +1,7 @@ 7.5 一行代码让代码运行速度提高100倍 =================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png python一直被病垢运行速度太慢,但是实际上python的执行效率并不慢,慢的是python用的解释器Cpython运行效率太差。 @@ -278,8 +278,4 @@ f_add就是一个动态生成的机器码函数,我们可以把它想象成C numba所完成的工作就是:解析Python函数的ast语法树并加以改造,添加类型信息;将带类型信息的ast语法树通过llvmpy动态地转换为机器码函数,然后再通过和ctypes类似的技术为机器码函数创建包装函数供Python调用。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_06.rst b/source/c07/c07_06.rst index 4d82163..b6a450e 100644 --- a/source/c07/c07_06.rst +++ b/source/c07/c07_06.rst @@ -1,7 +1,7 @@ 7.6 新一代的调试神器:PySnooper =============================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 对于每个程序开发者来说,调试几乎是必备技能。 @@ -135,7 +135,7 @@ PySnooper 如此一来,PySnooper 会在 ``out["foo"]`` 值有变化时,也将其打印出来 -|image1| +.. image:: http://image.iswbm.com/20201114183018.png watch 参数,接收一个可迭代对象(可以是list 或者 tuple),里面的元素为字符串表达式,什么意思呢?看下面例子就知道了 @@ -187,7 +187,7 @@ tuple),里面的元素为字符串表达式,什么意思呢?看下面例 效果如下 -|image2| +.. image:: http://image.iswbm.com/20201114193131.png 3.5 设置最大的输出长度 ~~~~~~~~~~~~~~~~~~~~~~ @@ -225,7 +225,7 @@ PySnooper 同样支持多线程的调试,通过设置参数 效果如下 -|image3| +.. image:: http://image.iswbm.com/20201114194449.png 2.7 自定义对象的格式输出 ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -287,7 +287,7 @@ PySnooper 在打印对象的调试信息时,会逐个判断它是否是 Person 运行一下,观察一下效果。 -|image4| +.. image:: http://image.iswbm.com/20201114201042.png 如果你要自定义格式输出的有很多个类型,那么 ``custom_repr`` 参数的值可以这么写 @@ -328,12 +328,4 @@ PySnooper 在打印对象的调试信息时,会逐个判断它是否是 Person 以上就是明哥今天给大家介绍的一款调试神器(\ ``PySnooper``\ ) 的详细使用手册,是不是觉得还不错? -|image5| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20201114183018.png -.. |image2| image:: http://image.iswbm.com/20201114193131.png -.. |image3| image:: http://image.iswbm.com/20201114194449.png -.. |image4| image:: http://image.iswbm.com/20201114201042.png -.. |image5| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_07.rst b/source/c07/c07_07.rst index 34b3afd..855272a 100644 --- a/source/c07/c07_07.rst +++ b/source/c07/c07_07.rst @@ -1,7 +1,7 @@ 7.7 比open更好用、更优雅的读取文件 ================================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 使用 open 函数去读取文件,似乎是所有 Python 工程师的共识。 @@ -277,7 +277,7 @@ fileinput 若你没有传入任何的勾子,fileinput 默认使用的是 open 函数。 -|image1| +.. image:: http://image.iswbm.com/image-20210227095708676.png ``fileinput`` 为我们内置了两种勾子供你使用 @@ -446,9 +446,4 @@ fileinput 是对 open 函数的再次封装,在仅需读取数据的场景中 就无能为力啦,本身从 fileinput 的命名上就知道这个模块只专注于输入(读)而不是输出(写)。 -|image2| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/image-20210227095708676.png -.. |image2| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_08.rst b/source/c07/c07_08.rst index 8af9138..b12b254 100644 --- a/source/c07/c07_08.rst +++ b/source/c07/c07_08.rst @@ -1,7 +1,7 @@ 7.8 像操作路径一样,操作嵌套字典 ================================ -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 在使用前先安装它,要注意的是该模块只能在 Python 3.8+ 中使用 @@ -44,8 +44,4 @@ 更多案例,请前往 `官方文档 `__ 查阅。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_09.rst b/source/c07/c07_09.rst index 1e56d71..021ef1a 100644 --- a/source/c07/c07_09.rst +++ b/source/c07/c07_09.rst @@ -1,7 +1,7 @@ 7.9 读取文件中任意行的数据 ========================== -|image0| +.. image:: http://image.iswbm.com/20200804124133.png ``linecache`` 是 Python 中的一个内置模块。 @@ -24,8 +24,4 @@ >>> -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_10.rst b/source/c07/c07_10.rst index bd38534..d1c4e5d 100644 --- a/source/c07/c07_10.rst +++ b/source/c07/c07_10.rst @@ -1,7 +1,7 @@ 7.10 让你的装饰器写得更轻松的神库 ================================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 本篇文章会为你介绍的是一个已经存在十三年,但是依旧不红的库 decorator,好像很少有人知道他的存在一样。 @@ -42,12 +42,12 @@ Python 中被装饰器装饰后的方法长得更像装饰前的方法。 有一些比较聪明的同学,会利用 PyCharm 来自动生成装饰器模板 -|image1| +.. image:: http://image.iswbm.com/image-20210420211718252.png 然后要使用的时候,直接敲入 ``deco`` 就会生成一个简单的生成器代码,提高编码的准备效率 -|image2| +.. image:: http://image.iswbm.com/deco.gif 2. 使用神库 ----------- @@ -246,10 +246,4 @@ deco 这么棒的一个库,推荐你使用起来。 -|image3| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/image-20210420211718252.png -.. |image2| image:: http://image.iswbm.com/deco.gif -.. |image3| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_11.rst b/source/c07/c07_11.rst index ef595c2..4c3e87f 100644 --- a/source/c07/c07_11.rst +++ b/source/c07/c07_11.rst @@ -1,7 +1,7 @@ 7.11 国际化模块,让翻译更优雅 ============================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 国际化与本地化 -------------- @@ -73,8 +73,4 @@ gettext 是一套 GNU下的国际化工具。主要有工具: >>> _('hello world') '你好世界' -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_12.rst b/source/c07/c07_12.rst index ca97650..fe6c265 100644 --- a/source/c07/c07_12.rst +++ b/source/c07/c07_12.rst @@ -1,7 +1,7 @@ 7.12 非常好用的调度模块 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png Python 自带一个调度器模块\ ``sched``\ ,它能为你实现优先级队列/延迟队列和定时队列。 @@ -21,7 +21,7 @@ Python 代码运行以后,会卡在\ ``sch.run()``\ 这里,5秒钟以后执行\ ``do_work('iswbm')``\ ,运行效果如下图所示: -|image1| +.. image:: http://image.iswbm.com/20210521215217.png 其中,\ ``sch.enter()``\ 的第一个参数为延迟的时间,单位为秒,第二个参数为优先级,数字越小优先级越高。当两个任务同时要执行时,优先级高的先执行。但需要注意的是,如果你这样写: @@ -39,7 +39,7 @@ Python 那么先打印出来的是\ ``你好:python`` -|image2| +.. image:: http://image.iswbm.com/20210521215257.png 为什么这里优先级失效了?1的优先级大于2,应该先运行下面的才对啊。 @@ -65,7 +65,7 @@ Python 运行效果如下图所示: -|image3| +.. image:: http://image.iswbm.com/20210521215402.png ``sch.enterabs()``\ 的第一个参数是任务开始时间的时间戳,这是一个绝对时间,这个时间可以使用datetime模块来生成,或者其他你熟悉的方式。后面的参数和\ ``sch.enter()``\ 完全一样。 @@ -89,13 +89,6 @@ Python argument参数对应的元组存放普通参数,kwargs对应的字典存放带参数名的参数。 -本文来源于:公众号"未闻Code",作者:kingname - -|image4| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20210521215217.png -.. |image2| image:: http://image.iswbm.com/20210521215257.png -.. |image3| image:: http://image.iswbm.com/20210521215402.png -.. |image4| image:: http://image.iswbm.com/20200607174235.png +本文来源于:公众号"未闻Code",作者:kingname +.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_13.rst b/source/c07/c07_13.rst index 7efe641..fc996a9 100644 --- a/source/c07/c07_13.rst +++ b/source/c07/c07_13.rst @@ -1,7 +1,7 @@ 7.13 实现字典的点式操作 ======================= -|image0| +.. image:: http://image.iswbm.com/20200804124133.png 字典是 Python 中基础的数据结构之一,字典的使用,可以说是非常的简单粗暴,但即便是这样一个与世无争的数据结构,仍然有很多人 @@ -268,8 +268,4 @@ Munch 支持序列化为 JSON 或者 YAML 格式的字符串对象 也正是因为这样,原生字典至今还是不可替代的存在。 -|image1| - -.. |image0| image:: http://image.iswbm.com/20200804124133.png -.. |image1| image:: http://image.iswbm.com/20200607174235.png - +.. image:: http://image.iswbm.com/20200607174235.png From a6bcb7e0e12f0459b2cba3972b0383f2a972b8a6 Mon Sep 17 00:00:00 2001 From: iswbm Date: Mon, 7 Feb 2022 21:11:31 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=89=E7=AF=87?= =?UTF-8?q?=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 + source/c03/c03_13.md | 85 +++++++ source/c03/c03_13.rst | 89 ++++++++ source/c07/c07_14.md | 173 ++++++++++++++ source/c07/c07_14.rst | 204 +++++++++++++++++ source/c07/c07_15.md | 451 +++++++++++++++++++++++++++++++++++++ source/c07/c07_15.rst | 512 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1517 insertions(+) create mode 100644 source/c03/c03_13.md create mode 100644 source/c03/c03_13.rst create mode 100644 source/c07/c07_14.md create mode 100644 source/c07/c07_14.rst create mode 100644 source/c07/c07_15.md create mode 100644 source/c07/c07_15.rst diff --git a/README.md b/README.md index 2db7937..ec33cff 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ * [# 3.10 Python装饰器的六种写法](https://magic.iswbm.com/c03/c03_10.html) * [# 3.11 Python 读取文件的六种方式](https://magic.iswbm.com/c03/c03_11.html) * [# 3.12 调用函数的九种方法](https://magic.iswbm.com/c03/c03_12.html) + * [# 3.13 创造 "新语法" 的黑科技](https://magic.iswbm.com/c03/c03_13.html) - **第四章:魔法进阶扫盲** * [# 4.1 精通上下文管理器](https://magic.iswbm.com/c04/c04_01.html) * [# 4.2 深入理解描述符](https://magic.iswbm.com/c04/c04_02.html) @@ -179,6 +180,8 @@ * [# 7.11 国际化模块,让翻译更优雅](https://magic.iswbm.com/c07/c07_11.html) * [# 7.12 非常好用的调度模块](https://magic.iswbm.com/c07/c07_12.html) * [# 7.13 实现字典的点式操作](https://magic.iswbm.com/c07/c07_13.html) + * [# 7.14 使用 trypackage 试用新库](https://magic.iswbm.com/c07/c07_14.html) + * [# 7.15 利用 streamlit 傻瓜式构建可视化web应用](https://magic.iswbm.com/c07/c07_15.html) ## 写在最后 diff --git a/source/c03/c03_13.md b/source/c03/c03_13.md new file mode 100644 index 0000000..a7d79da --- /dev/null +++ b/source/c03/c03_13.md @@ -0,0 +1,85 @@ +# 3.13 创造 "新语法" 的黑科技 + +![](http://image.iswbm.com/20200804124133.png) + +通常我们遍历一个元素为 5-10 的数组,会这么写 + +```python +>>> for i in range(5,11): +... print(i) +... +5 +6 +7 +8 +9 +10 +``` + +写法虽然简单,但总有一种不够直观的样子。 + +今天介绍一个黑科技方法,可以让这种写法更加直观,不够请谨慎使用,因为这个方法有点 "逆天",会让人误以为是 Python 又出了什么新语法。 + +最后的效果是这样子的。 + +```python +>>> for i in 5|到|10: +... print(i) +... +5 +6 +7 +8 +9 +``` + +`|到|` 很容易让人误以为是什么新的语法? + +其实不是的,`|到|` 应该分为 `|` 、`到`、`|` 这三个部分,下面我们一一讲解。 + +第一和第三的 `|` 是同个意思,它就是一个普通的运算符,通常我们使用 `or` 关键字来替代它,导致很多人对这个符号比较陌生。 + +这边是一个简单的例子,当两边 `|` 两边有一边为 True 就会返回 True + +``` python +>>> if True | False: +... print("ok") +... +ok +>>> +>>> if False | False: +... print("ok") +... +>>> +``` + +基本上所有的运算符都可以通过魔法方法来重新定义运算符的逻辑,这个过程叫做运算符重载, `|` 也不例外。 + +控制 `|` 的魔法方法是 `__or__` 和 `__xor__` + +讲完了第一个和第三个字符,现在说说第二个字符 `到` + +`到` 实际上是一个类的实例,上面为了神秘,我没有事先给出完整代码 + +定义一个 Magic 的类,用于改变 range 的 `|` 方法 + +```python +>>> class Magic(object): +... def __init__(self, func): +... self.func = func +... def __or__(self, other): +... return self.func(other) +... def __ror__(self, other): +... self.func = partial(self.func, other) +... return self +... +>>> +>>> 到 = Magic(range) +``` + +总结一下,这三者如何起作用的? + +- `到` 是 Magic 类的一个实例 +- `__or__` 定义的是 `到` 实例右侧遇到 `|` 的行为 +- `__xor__` 定义的是 `到` 实例左侧遇到 `|` 的行为 + diff --git a/source/c03/c03_13.rst b/source/c03/c03_13.rst new file mode 100644 index 0000000..63dd0f3 --- /dev/null +++ b/source/c03/c03_13.rst @@ -0,0 +1,89 @@ +3.13 创造 "新语法" 的黑科技 +=========================== + +.. image:: http://image.iswbm.com/20200804124133.png + +通常我们遍历一个元素为 5-10 的数组,会这么写 + +.. code:: python + +>>> for i in range(5,11): + ... print(i) + ... + 5 + 6 + 7 + 8 + 9 + 10 + +写法虽然简单,但总有一种不够直观的样子。 + +今天介绍一个黑科技方法,可以让这种写法更加直观,不够请谨慎使用,因为这个方法有点 +"逆天",会让人误以为是 Python 又出了什么新语法。 + +最后的效果是这样子的。 + +.. code:: python + +>>> for i in 5|到|10: + ... print(i) + ... + 5 + 6 + 7 + 8 + 9 + +``|到|`` 很容易让人误以为是什么新的语法? + +其实不是的,\ ``|到|`` 应该分为 ``|`` 、\ ``到``\ 、\ ``|`` +这三个部分,下面我们一一讲解。 + +第一和第三的 ``|`` 是同个意思,它就是一个普通的运算符,通常我们使用 +``or`` 关键字来替代它,导致很多人对这个符号比较陌生。 + +这边是一个简单的例子,当两边 ``|`` 两边有一边为 True 就会返回 True + +.. code:: python + +>>> if True | False: + ... print("ok") + ... + ok +>>> +>>> if False | False: + ... print("ok") + ... +>>> + +基本上所有的运算符都可以通过魔法方法来重新定义运算符的逻辑,这个过程叫做运算符重载, +``|`` 也不例外。 + +控制 ``|`` 的魔法方法是 ``__or__`` 和 ``__xor__`` + +讲完了第一个和第三个字符,现在说说第二个字符 ``到`` + +``到`` 实际上是一个类的实例,上面为了神秘,我没有事先给出完整代码 + +定义一个 Magic 的类,用于改变 range 的 ``|`` 方法 + +.. code:: python + +>>> class Magic(object): + ... def __init__(self, func): + ... self.func = func + ... def __or__(self, other): + ... return self.func(other) + ... def __ror__(self, other): + ... self.func = partial(self.func, other) + ... return self + ... +>>> +>>> 到 = Magic(range) + +总结一下,这三者如何起作用的? + +- ``到`` 是 Magic 类的一个实例 +- ``__or__`` 定义的是 ``到`` 实例右侧遇到 ``|`` 的行为 +- ``__xor__`` 定义的是 ``到`` 实例左侧遇到 ``|`` 的行为 diff --git a/source/c07/c07_14.md b/source/c07/c07_14.md new file mode 100644 index 0000000..00cbd0c --- /dev/null +++ b/source/c07/c07_14.md @@ -0,0 +1,173 @@ +# 7.14 使用 trypackage 试用新库 + +![](http://image.iswbm.com/20200804124133.png) + +听到某些人说 xx 库非常好用的时候,我们总是忍不住想要去亲自试试。 + +有一些库,之所以好用,是对一些库做了更高级的封闭,你装了这个库,就会附带装了 n 多依赖库,就比如前一篇文章介绍的 streamlit 来说,依赖包就达 90 几个之多? + +比百度全家桶,还 tm 的全家桶啊... + +也正是因为害怕会污染我的全局 Python 环境,我通常在试用新包的时候,都会使用 venv 创建虚拟环境,再去安装,完事之后,再清理虚拟环境即可。 + +有没有发现,整个流程,其实还是挺麻烦的。 + +刚好昨天晚上,Github 上瞎逛,被我发现一个库,可以解决我一直以来的烦扰。 + +这个库叫 `trypackage`,为试库而生的库。 + +整体的效果可以看下面这张动图 + +![](http://image.iswbm.com/Kapture 2022年01月11日 at 00.09.07.gif) + +当你使用 `try xx` 命令时,它会做哪些事呢? + +- 安装指定版本的 Python 解释器 +- 创建临时的虚拟环境 +- 激活虚拟环境 +- 在虚拟环境中安装你要试用的 Python 库 +- 直接进入 Python Shell 模式 +- 自动将你要试用的库导入进来 + +## 1. 如何安装 + +一条命令就可以安装它 + +```shell +python3 -m pip install trypackage +``` + +可以看到 trypackage 只依赖一个 click 命令行库,还是很轻量的 + +![](http://image.iswbm.com/20220111000209.png) + +其实不是这样,try 会基于 virtualenv 创建虚拟环境,因此还要安装 virtualenv 和 virtualenvwrapper + +```bash +python3 -m pip install virtualenv virtualenvwrapper +``` + +## 2. 基本使用 + +使用 `try requests`,try 就会创建一个虚拟环境,然后在该虚拟环境中,安装 requests ,安装完成后,自动进入 Python Shell 的模式,并且自动导入好你要试用的包 + +![](http://image.iswbm.com/20220111002117.png) + +最贴心的是,试用完后,退出 Python Shell ,会自动清理掉虚拟环境。 + +## 3. 更多用法 + +### 指定 python 版本 + +我的环境没有安装 Python 3.8,通过 `-p` 参数,可以指定 Python 3.8 ,安装的过程太快,快得让我有点怀疑这是不是真正的去安装 Python 3.8 解释器了。 + +![](http://image.iswbm.com/20220111003943.png) + +也可以直接指定本地的 Python 版本,例如 + +```bash +try requests -p /usr/bin/python3.7.1 +``` + +### 指定运行模式 + +Try 直接的运行模式非常多 + +**1、当你不指定时,默认使用 python shell 的模式** + +```bash +# 二者等价 +try requests +try requests --shell python +``` + +**2、使用 ipython 有两种指定方式** + +```bash +# 二者等价 +try requests --ipython +try requests --shell ipython +``` + +![](http://image.iswbm.com/20220111003332.png) + +**3、使用 ptpython 或者 ptipython** + +这两种模式都有代码提示与自动补全功能 + +![](http://image.iswbm.com/20220111003750.png) + +**4、使用 bpython 模式** + +Bpython 的代码提示与补全比 ptpython 、ptipython ,更强一点,其他的区别还没试用到。 + +![](http://image.iswbm.com/20220111004939.png) + +### 在编辑器中打开 + +```bash +try requests --editor +``` + +### 指定 Github 仓库包 + +```bash +# 语法示例 +try / + +# 安装 Github 上的 Kenneth/requests 上的 master 版本 +try kennethreitz/requests +``` + +### 指定已经存在的虚拟环境 + +```bash +try requests --virtualenv ~/.try/sandbox +``` + +### 持久化虚拟环境 + +默认情况下,你退出后,会自动清理掉虚拟环境,若有特殊需要,可指定 `--keep` 参数来持久化虚拟环境 + +![](http://image.iswbm.com/20220111005246.png) + +### 指定虚拟环境的目录 + +默认情况下,try 会将虚拟环境创建在一个默认的目录中,这个目录比较深,不容易记住,你可以指定 `--tmpdir` 参数,告诉 try 要将虚拟环境创建在这里,这个参数对于想要持久化虚拟环境的人会很有用。 + +```bash +try requests --tmpdir ~/.try +``` + +## 4. 配置文件 + +try 虽然提供命令行入参的方式来识别用户选项,但对于一些用户来说,更希望能一次性修改 try 的默认选项,而不用每次都指定多个参数。 + +这时候,可以在你的 APP 目录下新增一个 config.ini 文件,内容模板如下 + +```ini +[env] +virtualenv=~/.try/sandbox +python=3.8 +shell=ipython +keep=false +always_use_editor=false +tmpdir=~/.try +``` + +所谓的 APP 目录,在不同的系统中是不一样的,可以使用如下代码来查看 + +```python +>>> import click +>>> click.get_app_dir("try") +'/Users/iswbm/Library/Application Support/try' +>>> +``` + +有了 config.ini,再次 try ,就会发现效果与配置一样的预期一致。 + +![](http://image.iswbm.com/20220111010900.png) + +## 5. 总结一下 + +Try 是一个非常实用的命令行工具,可以说完全击中我的痛点,能把这样一个库做出来,真的是创意十足,再一次印证 Python 是懒人第一语言 。。 \ No newline at end of file diff --git a/source/c07/c07_14.rst b/source/c07/c07_14.rst new file mode 100644 index 0000000..8ab62bf --- /dev/null +++ b/source/c07/c07_14.rst @@ -0,0 +1,204 @@ +7.14 使用 trypackage 试用新库 +============================= + +.. image:: http://image.iswbm.com/20200804124133.png + +听到某些人说 xx 库非常好用的时候,我们总是忍不住想要去亲自试试。 + +有一些库,之所以好用,是对一些库做了更高级的封闭,你装了这个库,就会附带装了 +n 多依赖库,就比如前一篇文章介绍的 streamlit 来说,依赖包就达 90 +几个之多? + +比百度全家桶,还 tm 的全家桶啊... + +也正是因为害怕会污染我的全局 Python +环境,我通常在试用新包的时候,都会使用 venv +创建虚拟环境,再去安装,完事之后,再清理虚拟环境即可。 + +有没有发现,整个流程,其实还是挺麻烦的。 + +刚好昨天晚上,Github 上瞎逛,被我发现一个库,可以解决我一直以来的烦扰。 + +这个库叫 ``trypackage``\ ,为试库而生的库。 + +整体的效果可以看下面这张动图 + +.. image:: http://image.iswbm.com/Kapture%202022-01-11%20at%2000年09月07日.gif + +当你使用 ``try xx`` 命令时,它会做哪些事呢? + +- 安装指定版本的 Python 解释器 +- 创建临时的虚拟环境 +- 激活虚拟环境 +- 在虚拟环境中安装你要试用的 Python 库 +- 直接进入 Python Shell 模式 +- 自动将你要试用的库导入进来 + +1. 如何安装 +----------- + +一条命令就可以安装它 + +.. code:: shell + + python3 -m pip install trypackage + +可以看到 trypackage 只依赖一个 click 命令行库,还是很轻量的 + +.. image:: http://image.iswbm.com/20220111000209.png + +其实不是这样,try 会基于 virtualenv 创建虚拟环境,因此还要安装 +virtualenv 和 virtualenvwrapper + +.. code:: bash + + python3 -m pip install virtualenv virtualenvwrapper + +2. 基本使用 +----------- + +使用 ``try requests``\ ,try +就会创建一个虚拟环境,然后在该虚拟环境中,安装 requests +,安装完成后,自动进入 Python Shell 的模式,并且自动导入好你要试用的包 + +.. image:: http://image.iswbm.com/20220111002117.png + +最贴心的是,试用完后,退出 Python Shell ,会自动清理掉虚拟环境。 + +3. 更多用法 +----------- + +指定 python 版本 +~~~~~~~~~~~~~~~~ + +我的环境没有安装 Python 3.8,通过 ``-p`` 参数,可以指定 Python 3.8 +,安装的过程太快,快得让我有点怀疑这是不是真正的去安装 Python 3.8 +解释器了。 + +.. image:: http://image.iswbm.com/20220111003943.png + +也可以直接指定本地的 Python 版本,例如 + +.. code:: bash + + try requests -p /usr/bin/python3.7.1 + +指定运行模式 +~~~~~~~~~~~~ + +Try 直接的运行模式非常多 + +**1、当你不指定时,默认使用 python shell 的模式** + +.. code:: bash + + # 二者等价 + try requests + try requests --shell python + +**2、使用 ipython 有两种指定方式** + +.. code:: bash + + # 二者等价 + try requests --ipython + try requests --shell ipython + +.. image:: http://image.iswbm.com/20220111003332.png + +**3、使用 ptpython 或者 ptipython** + +这两种模式都有代码提示与自动补全功能 + +.. image:: http://image.iswbm.com/20220111003750.png + +**4、使用 bpython 模式** + +Bpython 的代码提示与补全比 ptpython 、ptipython +,更强一点,其他的区别还没试用到。 + +.. image:: http://image.iswbm.com/20220111004939.png + +在编辑器中打开 +~~~~~~~~~~~~~~ + +.. code:: bash + + try requests --editor + +指定 Github 仓库包 +~~~~~~~~~~~~~~~~~~ + +.. code:: bash + + # 语法示例 + try / + + # 安装 Github 上的 Kenneth/requests 上的 master 版本 + try kennethreitz/requests + +指定已经存在的虚拟环境 +~~~~~~~~~~~~~~~~~~~~~~ + +.. code:: bash + + try requests --virtualenv ~/.try/sandbox + +持久化虚拟环境 +~~~~~~~~~~~~~~ + +默认情况下,你退出后,会自动清理掉虚拟环境,若有特殊需要,可指定 +``--keep`` 参数来持久化虚拟环境 + +.. image:: http://image.iswbm.com/20220111005246.png + +指定虚拟环境的目录 +~~~~~~~~~~~~~~~~~~ + +默认情况下,try +会将虚拟环境创建在一个默认的目录中,这个目录比较深,不容易记住,你可以指定 +``--tmpdir`` 参数,告诉 try +要将虚拟环境创建在这里,这个参数对于想要持久化虚拟环境的人会很有用。 + +.. code:: bash + + try requests --tmpdir ~/.try + +4. 配置文件 +----------- + +try +虽然提供命令行入参的方式来识别用户选项,但对于一些用户来说,更希望能一次性修改 +try 的默认选项,而不用每次都指定多个参数。 + +这时候,可以在你的 APP 目录下新增一个 config.ini 文件,内容模板如下 + +.. code:: ini + + [env] + virtualenv=~/.try/sandbox + python=3.8 + shell=ipython + keep=false + always_use_editor=false + tmpdir=~/.try + +所谓的 APP 目录,在不同的系统中是不一样的,可以使用如下代码来查看 + +.. code:: python + +>>> import click +>>> click.get_app_dir("try") + '/Users/iswbm/Library/Application Support/try' +>>> + +有了 config.ini,再次 try ,就会发现效果与配置一样的预期一致。 + +.. image:: http://image.iswbm.com/20220111010900.png + +5. 总结一下 +----------- + +Try +是一个非常实用的命令行工具,可以说完全击中我的痛点,能把这样一个库做出来,真的是创意十足,再一次印证 +Python 是懒人第一语言 。。 diff --git a/source/c07/c07_15.md b/source/c07/c07_15.md new file mode 100644 index 0000000..28cab97 --- /dev/null +++ b/source/c07/c07_15.md @@ -0,0 +1,451 @@ +# 7.15 利用 streamlit 傻瓜式构建可视化web应用 + +![](http://image.iswbm.com/20200804124133.png) + +正常在学习一个新框架之前, 肯定要先调研下这个框架究竟能做些什么事吧? + +但对于 streamlit 来说,请你相信我,这是一个你可以无脑去学习的框架,我之所以这么说,是因为我相信终有一天,你一定能用得上它。 + +如果你真的需要一些理由的话,那我随便给你举几个例子: + +- 做数据分析的同学,想要把数据分析的成果做成应用展示给其他人,怎么办? +- 想做一些用户数据的收集,但某些公有平台又却仅有收集,没有对应的开发能力提供数据的处理与反馈,怎么办? + +难道真的要为了这种简单的需求,去折腾 html + css + js + flask (or django) 吗? + +这是大多数非专业开发者的痛点,也是 streamlit 这个框架流行开来的主要原因。 + +Streamlit 是一个用于机器学习、数据可视化的 Python 框架,它能几行代码就构建出一个精美的在线 app 应用。 + +它能做什么,取决于你想干什么? + +streamlit 的功能强大,要学习的函数虽然多,但非常容易上手,学习成本却远比 前端+Flask 来得低得低。接下来,我会一一介绍。 + +## 1. 如何安装? + +和安装其他包一样,安装 streamlit 非常简单,一条命令即可 + +```bash +➜ pip install streamlit +``` + +考虑到 streamlit 会附带安装比较多的工具依赖包,为了不污染当前的主要环境,我使用 venv 新建一个虚拟环境。 + +```bash +➜ python3 -m venv . +``` + +然后使用如下命令进入该虚拟环境 + +```bash +➜ source ./venv/bin/activate +``` + +接下来,再安装 streamlit ,命令在上边。 + +安装的包比较多(数了下竟然接近 92 个?),过程也会很久,需要点耐心 + +```bash +➜ pip list | wc -l + 92 +``` + +在安装过程中,可能会遇到一些问题,但也不一定,这取决于你的机器,如遇到问题请自行借助搜索引擎解决。 + +## 2. 入门示例 + +Streamlit 提供了一些入门示例,执行如下命令即可 + +```bash +➜ streamlit hello +``` + +执行后 streamlit 会自动打开浏览器加载一个本地页面 `http://localhost:8501/` + +这里面有很多的 demo,你可以看一下,这些 Demo 还有对应的配套代码 + +![](http://image.iswbm.com/Kapture 2021年12月18日 at 10.43.41.gif) + +这些代码直接拷贝保存,就可以在本地直接通过如下命令直接运行 + +```bash +➜ streamlit run st-demo.py +``` + +## 2. Markdown 文本 + +导入 streamlit 后,就可以直接使用 st.markdown() 初始化,调用不同的方法,就可以往文档对象中填入内容 + +- st.title():文章大标题 +- st.header():一级标题 +- st.subheader():二级标题 +- st.text():文本 +- st.code():代码,同时可设置代码的语言,显示的时候会高亮 +- st.latex():latex 公式 +- st.caption():小字体文本 + +如下我自己写的一个小 Demo,供你参考 + +```python +import streamlit as st + +# markdown +st.markdown('Streamlit Demo') + +# 设置网页标题 +st.title('一个傻瓜式构建可视化 web的 Python 神器 -- streamlit') + +# 展示一级标题 +st.header('1. 安装') + +st.text('和安装其他包一样,安装 streamlit 非常简单,一条命令即可') +code1 = '''pip3 install streamlit''' +st.code(code1, language='bash') + + +# 展示一级标题 +st.header('2. 使用') + +# 展示二级标题 +st.subheader('2.1 生成 Markdown 文档') + +# 纯文本 +st.text('导入 streamlit 后,就可以直接使用 st.markdown() 初始化') + +# 展示代码,有高亮效果 +code2 = '''import streamlit as st +st.markdown('Streamlit Demo')''' +st.code(code2, language='python') +``` + +Streamlit 运行的方式 与普通的脚本 有所不同,应该使用 `streamlit run st-demo.py` + +![](http://image.iswbm.com/20211217204946.png) + +运行后就会自动打开浏览器加载这个页面,如果没有自动打开,也可以手动拷贝上图中的链接打开访问。 + +是不是有点那个味了?就这,还只是开胃菜〜 + +![](http://image.iswbm.com/20211217210705.png) + +## 3. 数据图表支持 + +### 3.1 图表组件 + +关于数据的展示,streamlit 由两个组件进行支持 + +- table:普通的表格,用于静态数据的展示 +- dataframe:高级的表格,可以进行数据的操作,比如排序 + +Table 的示例 + +```python +df = pd.DataFrame( + np.random.randn(10, 5), + columns=('第%d列' % (i+1) for i in range(5)) +) + +st.table(df) +``` + +效果如下 + +![](http://image.iswbm.com/20211217213755.png) + +Datafram 的示例 + +```python +df = pd.DataFrame( + np.random.randn(10, 5), + columns=('第%d列' % (i+1) for i in range(5)) +) + +st.dataframe(df.style.highlight_max(axis=0)) +``` + +效果如下,可以看到在图示外,有个向下的小箭头,你点一下,就会进行排序 + +除此之外,你还能看到我对最大值进行了高亮显示,原因是我传入的参数是 df.style.highlight_max(axis=0) + +![](http://image.iswbm.com/20211217214130.png) + +其实还有 n 多种样式,比如: + +- highlight_null:空值高亮 +- highlight_min:最小值高亮 +- highlight_max:最大值高亮 +- highlight_between:某区间内的值高亮 +- highlight_quantile:暂没用过 + +这些你都可以在源代码中找到示例 + +### 3.2 监控组件 + +在采集到一些监控数据后,若你需要做一个监控面板, streamlit 也为你提供的 metric 组件 + +如下代码创建 三个指标,并且填入对应的数据 + +```python +col1, col2, col3 = st.columns(3) +col1.metric("Temperature", "70 °F", "1.2 °F") +col2.metric("Wind", "9 mph", "-8%") +col3.metric("Humidity", "86%", "4%") +``` + +刷新页面,就能看到下面的效果 + +![](http://image.iswbm.com/20211217220958.png) + +### 3.3 原生图表组件 + +Streamlit 原生支持多种图表: + +- st.line_chart:折线图 +- st.area_chart:面积图 +- st.bar_chart:柱状图 +- st.map:地图 + +下面一一展示 + +**折线图** + +```python +chart_data = pd.DataFrame( + np.random.randn(20, 3), + columns=['a', 'b', 'c']) + +st.line_chart(chart_data) +``` + +![](http://image.iswbm.com/20211217221658.png) + +**面积图** + +```python +chart_data = pd.DataFrame( + np.random.randn(20, 3), + columns = ['a', 'b', 'c']) + +st.area_chart(chart_data) +``` + +![](http://image.iswbm.com/20211217223103.png) + +**柱状图** + +```python +chart_data = pd.DataFrame( + np.random.randn(50, 3), + columns = ["a", "b", "c"]) +st.bar_chart(chart_data) +``` + +![](http://image.iswbm.com/20211217223257.png) + +**地图** + +```python +df = pd.DataFrame( + np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], + columns=['lat', 'lon'] +) +st.map(df) +``` + +![](http://image.iswbm.com/20211217223011.png) + +### 3.4 外部图表组件 + +Streamlit 的一些原生图表组件,虽然做到了傻瓜式,但仅能输入数据、高度和宽度,如果你想更漂亮的图表,就像 matplotlib.pyplot、Altair、vega-lite、Plotly、Bokeh、PyDeck、Graphviz 那样,streamlit 也提供了支持: + +- st.pyplot + +- st.bokeh_chart +- st.altair_chart +- st.altair_chart +- st.vega_lite_chart +- st.plotly_chart +- st.pydeck_chart +- st.graphviz_chart + +对于这部分,熟悉的同学自行尝试了,这里不再演示。 + +![](http://image.iswbm.com/20211217231312.png) + +## 4. 用户操作支持 + +前面 streamlit 都只是展示文本和数据,如果仅是如此,那 streamlit 也就 just so so + +对于那些不会前端,并且平时有需要写一些简单的页面的人说,能写一些交互界面才是硬需求。 + +庆幸的是,你平时在网页上、app 上能看到的交互组件,Streamlit 几乎都能支持。。 + +- button:按钮 +- download_button:文件下载 +- file_uploader:文件上传 +- checkbox:复选框 +- radio:单选框 +- selectbox:下拉单选框 +- multiselect:下拉多选框 +- slider:滑动条 +- select_slider:选择条 +- text_input:文本输入框 +- text_area:文本展示框 +- number_input:数字输入框,支持加减按钮 +- date_input:日期选择框 +- time_input:时间选择框 +- color_picker:颜色选择器 + +这些内容非常多,也比较简单,一个一个举例也没必要,大家直接去看 streamlit 源码里的注释即可。 + +![](http://image.iswbm.com/20211217230211.png) + +## 5. 多媒体组件 + +想要在页面上播放图片、音频和视频,可以使用 streamlit 的这三个组件: + +- st.image +- st.audio +- st.video + +![](http://image.iswbm.com/640.png) + +## 6. 状态组件 + +状态组件用来向用户展示当前程序的运行状态,包括: + +- progress:进度条,如游戏加载进度 +- spinner:等待提示 +- balloons:页面底部飘气球,表示祝贺 +- error:显示错误信息 +- warning:显示报警信息 +- info:显示常规信息 +- success:显示成功信息 +- exception:显示异常信息(代码错误栈) + +效果如下: + +![img](http://image.iswbm.com/640-20211217232315268.png) + +## 7. 页面布局 + +Streamlit 是自上而下渲染的,组件在页面上的排列顺序与代码的执行顺序一致。 + +一个精美的 web app ,只有上下单栏式的布局肯定是不够的。 + +实际上 streamlit 还提供了多种多样的布局: + +**st.sidebar:侧边栏** + +侧边栏可以做一些用户操作控件 + +![](http://image.iswbm.com/20211218110335.png) + +st.columns:列容器,处在同一个 columns 内组件,按照从左至右顺序展示 + +st.expander:隐藏信息,点击后可展开展示详细内容,如:展示更多 + +st.container:包含多组件的容器 + +st.empty:包含单组件的容器 + +## 8. 流程控制系统 + +Streamlit 是自上而下逐步渲染出来的,若你的应用场景需要对渲染做一些控制,streamlit 也有提供对应的方法 + +- st.stop:可以让 Streamlit 应用停止而不向下执行,如:验证码通过后,再向下运行展示后续内容。 +- st.form:表单,Streamlit 在某个组件有交互后就会重新执行页面程序,而有时候需要等一组组件都完成交互后再刷新(如:登录填用户名和密码),这时候就需要将这些组件添加到 form 中 +- st.form_submit_button:在 form 中使用,提交表单。 + +## 9. 缓存特性提升速度 + +当用户在页面上做一些操作的时候,比如输入数据,都会触发整个 streamlit 应用代码的重新执行,如果其中有读取外部数据的步骤(数 GB 的数据),那这种性能损耗是非常可怕的。 + +但 streamlit 提供了一个缓存装饰器,当要重新执行代码渲染页面的时候,就会先去缓存里查一下,如果代码或者数据没有发生变化,就直接调用缓存的结果即可。 + +使用方法也简单,在需要缓存的函数加上 @st.cache 装饰器即可。 + +```python +DATE_COLUMN = 'date/time' +DATA_URL = ('https://s3-us-west-2.amazonaws.com/' + 'streamlit-demo-data/uber-raw-data-sep14.csv.gz') + +@st.cache +def load_data(nrows): + data = pd.read_csv(DATA_URL, nrows=nrows) + lowercase = lambda x: str(x).lower() + data.rename(lowercase, axis='columns', inplace=True) + data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN]) + return data +``` + +## 10. 部署上线 + +在本地编写的 streamlit 应用,运行起来后只能在本地访问。 + +如果需要让别人也能访问这个应用,那你需要有一台服务器,这样才能通过公网ip进行访问 + +如果你需要服务器,可以点 [这个链接](https://www.aliyun.com/minisite/goods?taskPkg=1111ydsrwb&pkgSid=3650&userCode=x1rep02u) 领个卷有优惠。 + +另外,还有一个选择,就是使用 Heroku (https://heroku.com)部署你的应用。 + +Heroku是一个支持多种编程语言的云平台即服务,你只要注册一个帐号(听说网易和 QQ 邮箱不行,我使用的 Gmail 注册的) + +![](http://image.iswbm.com/20211218155410.png) + +然后创建自己的 app + +![](http://image.iswbm.com/20211218160550.png) + +这个 App 名字好像是要全网唯一,本想取个 hello-streamlit 的,发现早有人取过了。 + +![](http://image.iswbm.com/20211218160700.png) + +然后为你的应用,创建几个 Heroku 规定的文件 + +- requirements.txt:依赖包文件 +- setup.sh:安装脚本,主要是创建文件夹,写入配置文件 +- Procfile:启动脚本,告诉 Heroku 如何安装并启动应用 + +这些文件的编程有固定的格式,我这边编写好了一份模板下载地址 https://www.lanzout.com/ikMWkxqktgj + +![](http://image.iswbm.com/20211218163524.png) + +拿到了这份模板后,你就可以基于这份模板创建你的 git 仓库 + +``` +git init +git add --all +git commit -m "init" +``` + +然后部署到 Heroku + +``` +heroku login +heroku create +git push heroku master +heroku ps:scale web=1 +``` + +按照命令行输出的URL就可以访问你的应用了。 + +查看Heroku日志: + +``` +heroku logs --tail +``` + +要想使用自己域名,需要先通过Heroku验证。然后运行: + +``` +heroku domains:add hivecnstats.iswbm.com +``` + +使用 Heroku 唯一的缺点就是 Heroku 是需要梯子的,一般人访问不了,没条件的还是乖乖的备台服务器吧。 + +## 12. 总结一下 + +Streamlit 一个开箱即用的工具集,它可以让一个普通的个人开发者免于学习繁杂的前端知识,就可以轻松、快速的构建一个简洁、优雅的 web app 应用,这是 streamlit 最吸引人的地方。 + +对于从事数据分析,机器学习领域的人来说,它绝对是开发神器,但即使你不是这些领域的人,你肯定也会有搭建一个 web app 需求的时候,streamlit 正是你需要的。 \ No newline at end of file diff --git a/source/c07/c07_15.rst b/source/c07/c07_15.rst new file mode 100644 index 0000000..c74f7e4 --- /dev/null +++ b/source/c07/c07_15.rst @@ -0,0 +1,512 @@ +7.15 利用 streamlit 傻瓜式构建可视化web应用 +=========================================== + +.. image:: http://image.iswbm.com/20200804124133.png + +正常在学习一个新框架之前, 肯定要先调研下这个框架究竟能做些什么事吧? + +但对于 streamlit +来说,请你相信我,这是一个你可以无脑去学习的框架,我之所以这么说,是因为我相信终有一天,你一定能用得上它。 + +如果你真的需要一些理由的话,那我随便给你举几个例子: + +- 做数据分析的同学,想要把数据分析的成果做成应用展示给其他人,怎么办? +- 想做一些用户数据的收集,但某些公有平台又却仅有收集,没有对应的开发能力提供数据的处理与反馈,怎么办? + +难道真的要为了这种简单的需求,去折腾 html + css + js + flask (or django) +吗? + +这是大多数非专业开发者的痛点,也是 streamlit +这个框架流行开来的主要原因。 + +Streamlit 是一个用于机器学习、数据可视化的 Python +框架,它能几行代码就构建出一个精美的在线 app 应用。 + +它能做什么,取决于你想干什么? + +streamlit 的功能强大,要学习的函数虽然多,但非常容易上手,学习成本却远比 +前端+Flask 来得低得低。接下来,我会一一介绍。 + +1. 如何安装? +------------- + +和安装其他包一样,安装 streamlit 非常简单,一条命令即可 + +.. code:: bash + + ➜ pip install streamlit + +考虑到 streamlit +会附带安装比较多的工具依赖包,为了不污染当前的主要环境,我使用 venv +新建一个虚拟环境。 + +.. code:: bash + + ➜ python3 -m venv . + +然后使用如下命令进入该虚拟环境 + +.. code:: bash + + ➜ source ./venv/bin/activate + +接下来,再安装 streamlit ,命令在上边。 + +安装的包比较多(数了下竟然接近 92 个?),过程也会很久,需要点耐心 + +.. code:: bash + + ➜ pip list | wc -l + 92 + +在安装过程中,可能会遇到一些问题,但也不一定,这取决于你的机器,如遇到问题请自行借助搜索引擎解决。 + +2. 入门示例 +----------- + +Streamlit 提供了一些入门示例,执行如下命令即可 + +.. code:: bash + + ➜ streamlit hello + +执行后 streamlit 会自动打开浏览器加载一个本地页面 +``http://localhost:8501/`` + +这里面有很多的 demo,你可以看一下,这些 Demo 还有对应的配套代码 + +.. image:: http://image.iswbm.com/Kapture%202021-12-18%20at%20104341.gif + +这些代码直接拷贝保存,就可以在本地直接通过如下命令直接运行 + +.. code:: bash + + ➜ streamlit run st-demo.py + +2. Markdown 文本 +---------------- + +导入 streamlit 后,就可以直接使用 st.markdown() +初始化,调用不同的方法,就可以往文档对象中填入内容 + +- st.title():文章大标题 +- st.header():一级标题 +- st.subheader():二级标题 +- st.text():文本 +- st.code():代码,同时可设置代码的语言,显示的时候会高亮 +- st.latex():latex 公式 +- st.caption():小字体文本 + +如下我自己写的一个小 Demo,供你参考 + +.. code:: python + + import streamlit as st + + # markdown + st.markdown('Streamlit Demo') + + # 设置网页标题 + st.title('一个傻瓜式构建可视化 web的 Python 神器 -- streamlit') + + # 展示一级标题 + st.header('1. 安装') + + st.text('和安装其他包一样,安装 streamlit 非常简单,一条命令即可') + code1 = '''pip3 install streamlit''' + st.code(code1, language='bash') + + + # 展示一级标题 + st.header('2. 使用') + + # 展示二级标题 + st.subheader('2.1 生成 Markdown 文档') + + # 纯文本 + st.text('导入 streamlit 后,就可以直接使用 st.markdown() 初始化') + + # 展示代码,有高亮效果 + code2 = '''import streamlit as st + st.markdown('Streamlit Demo')''' + st.code(code2, language='python') + +Streamlit 运行的方式 与普通的脚本 有所不同,应该使用 +``streamlit run st-demo.py`` + +.. image:: http://image.iswbm.com/20211217204946.png + +运行后就会自动打开浏览器加载这个页面,如果没有自动打开,也可以手动拷贝上图中的链接打开访问。 + +是不是有点那个味了?就这,还只是开胃菜〜 + +.. image:: http://image.iswbm.com/20211217210705.png + +3. 数据图表支持 +--------------- + +3.1 图表组件 +~~~~~~~~~~~~ + +关于数据的展示,streamlit 由两个组件进行支持 + +- table:普通的表格,用于静态数据的展示 +- dataframe:高级的表格,可以进行数据的操作,比如排序 + +Table 的示例 + +.. code:: python + + df = pd.DataFrame( + np.random.randn(10, 5), + columns=('第%d列' % (i+1) for i in range(5)) + ) + + st.table(df) + +效果如下 + +.. image:: http://image.iswbm.com/20211217213755.png + +Datafram 的示例 + +.. code:: python + + df = pd.DataFrame( + np.random.randn(10, 5), + columns=('第%d列' % (i+1) for i in range(5)) + ) + + st.dataframe(df.style.highlight_max(axis=0)) + +效果如下,可以看到在图示外,有个向下的小箭头,你点一下,就会进行排序 + +除此之外,你还能看到我对最大值进行了高亮显示,原因是我传入的参数是 +df.style.highlight_max(axis=0) + +.. image:: http://image.iswbm.com/20211217214130.png + +其实还有 n 多种样式,比如: + +- highlight_null:空值高亮 +- highlight_min:最小值高亮 +- highlight_max:最大值高亮 +- highlight_between:某区间内的值高亮 +- highlight_quantile:暂没用过 + +这些你都可以在源代码中找到示例 + +3.2 监控组件 +~~~~~~~~~~~~ + +在采集到一些监控数据后,若你需要做一个监控面板, streamlit 也为你提供的 +metric 组件 + +如下代码创建 三个指标,并且填入对应的数据 + +.. code:: python + + col1, col2, col3 = st.columns(3) + col1.metric("Temperature", "70 °F", "1.2 °F") + col2.metric("Wind", "9 mph", "-8%") + col3.metric("Humidity", "86%", "4%") + +刷新页面,就能看到下面的效果 + +.. image:: http://image.iswbm.com/20211217220958.png + +3.3 原生图表组件 +~~~~~~~~~~~~~~~~ + +Streamlit 原生支持多种图表: + +- st.line_chart:折线图 +- st.area_chart:面积图 +- st.bar_chart:柱状图 +- st.map:地图 + +下面一一展示 + +**折线图** + +.. code:: python + + chart_data = pd.DataFrame( + np.random.randn(20, 3), + columns=['a', 'b', 'c']) + + st.line_chart(chart_data) + +.. image:: http://image.iswbm.com/20211217221658.png + +**面积图** + +.. code:: python + + chart_data = pd.DataFrame( + np.random.randn(20, 3), + columns = ['a', 'b', 'c']) + + st.area_chart(chart_data) + +.. image:: http://image.iswbm.com/20211217223103.png + +**柱状图** + +.. code:: python + + chart_data = pd.DataFrame( + np.random.randn(50, 3), + columns = ["a", "b", "c"]) + st.bar_chart(chart_data) + +.. image:: http://image.iswbm.com/20211217223257.png + +**地图** + +.. code:: python + + df = pd.DataFrame( + np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], + columns=['lat', 'lon'] + ) + st.map(df) + +.. image:: http://image.iswbm.com/20211217223011.png + +3.4 外部图表组件 +~~~~~~~~~~~~~~~~ + +Streamlit +的一些原生图表组件,虽然做到了傻瓜式,但仅能输入数据、高度和宽度,如果你想更漂亮的图表,就像 +matplotlib.pyplot、Altair、vega-lite、Plotly、Bokeh、PyDeck、Graphviz +那样,streamlit 也提供了支持: + +- st.pyplot + +- st.bokeh_chart + +- st.altair_chart + +- st.altair_chart + +- st.vega_lite_chart + +- st.plotly_chart + +- st.pydeck_chart + +- st.graphviz_chart + +对于这部分,熟悉的同学自行尝试了,这里不再演示。 + +.. image:: http://image.iswbm.com/20211217231312.png + +4. 用户操作支持 +--------------- + +前面 streamlit 都只是展示文本和数据,如果仅是如此,那 streamlit 也就 +just so so + +对于那些不会前端,并且平时有需要写一些简单的页面的人说,能写一些交互界面才是硬需求。 + +庆幸的是,你平时在网页上、app 上能看到的交互组件,Streamlit +几乎都能支持。。 + +- button:按钮 +- download_button:文件下载 +- file_uploader:文件上传 +- checkbox:复选框 +- radio:单选框 +- selectbox:下拉单选框 +- multiselect:下拉多选框 +- slider:滑动条 +- select_slider:选择条 +- text_input:文本输入框 +- text_area:文本展示框 +- number_input:数字输入框,支持加减按钮 +- date_input:日期选择框 +- time_input:时间选择框 +- color_picker:颜色选择器 + +这些内容非常多,也比较简单,一个一个举例也没必要,大家直接去看 streamlit +源码里的注释即可。 + +.. image:: http://image.iswbm.com/20211217230211.png + +5. 多媒体组件 +------------- + +想要在页面上播放图片、音频和视频,可以使用 streamlit 的这三个组件: + +- st.image +- st.audio +- st.video + +.. image:: http://image.iswbm.com/640.png + +6. 状态组件 +----------- + +状态组件用来向用户展示当前程序的运行状态,包括: + +- progress:进度条,如游戏加载进度 +- spinner:等待提示 +- balloons:页面底部飘气球,表示祝贺 +- error:显示错误信息 +- warning:显示报警信息 +- info:显示常规信息 +- success:显示成功信息 +- exception:显示异常信息(代码错误栈) + +效果如下: + +.. figure:: http://image.iswbm.com/640-20211217232315268.png + :alt: img + + img + +7. 页面布局 +----------- + +Streamlit 是自上而下渲染的,组件在页面上的排列顺序与代码的执行顺序一致。 + +一个精美的 web app ,只有上下单栏式的布局肯定是不够的。 + +实际上 streamlit 还提供了多种多样的布局: + +**st.sidebar:侧边栏** + +侧边栏可以做一些用户操作控件 + +.. image:: http://image.iswbm.com/20211218110335.png + +st.columns:列容器,处在同一个 columns 内组件,按照从左至右顺序展示 + +st.expander:隐藏信息,点击后可展开展示详细内容,如:展示更多 + +st.container:包含多组件的容器 + +st.empty:包含单组件的容器 + +8. 流程控制系统 +--------------- + +Streamlit +是自上而下逐步渲染出来的,若你的应用场景需要对渲染做一些控制,streamlit +也有提供对应的方法 + +- st.stop:可以让 Streamlit + 应用停止而不向下执行,如:验证码通过后,再向下运行展示后续内容。 +- st.form:表单,Streamlit + 在某个组件有交互后就会重新执行页面程序,而有时候需要等一组组件都完成交互后再刷新(如:登录填用户名和密码),这时候就需要将这些组件添加到 + form 中 +- st.form_submit_button:在 form 中使用,提交表单。 + +9. 缓存特性提升速度 +------------------- + +当用户在页面上做一些操作的时候,比如输入数据,都会触发整个 streamlit +应用代码的重新执行,如果其中有读取外部数据的步骤(数 GB +的数据),那这种性能损耗是非常可怕的。 + +但 streamlit +提供了一个缓存装饰器,当要重新执行代码渲染页面的时候,就会先去缓存里查一下,如果代码或者数据没有发生变化,就直接调用缓存的结果即可。 + +使用方法也简单,在需要缓存的函数加上 @st.cache 装饰器即可。 + +.. code:: python + + DATE_COLUMN = 'date/time' + DATA_URL = ('https://s3-us-west-2.amazonaws.com/' + 'streamlit-demo-data/uber-raw-data-sep14.csv.gz') + + @st.cache + def load_data(nrows): + data = pd.read_csv(DATA_URL, nrows=nrows) + lowercase = lambda x: str(x).lower() + data.rename(lowercase, axis='columns', inplace=True) + data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN]) + return data + +10. 部署上线 +------------ + +在本地编写的 streamlit 应用,运行起来后只能在本地访问。 + +如果需要让别人也能访问这个应用,那你需要有一台服务器,这样才能通过公网ip进行访问 + +如果你需要服务器,可以点 +`这个链接 `__ +领个卷有优惠。 + +另外,还有一个选择,就是使用 Heroku (https://heroku.com)部署你的应用。 + +Heroku是一个支持多种编程语言的云平台即服务,你只要注册一个帐号(听说网易和 +QQ 邮箱不行,我使用的 Gmail 注册的) + +.. image:: http://image.iswbm.com/20211218155410.png + +然后创建自己的 app + +.. image:: http://image.iswbm.com/20211218160550.png + +这个 App 名字好像是要全网唯一,本想取个 hello-streamlit +的,发现早有人取过了。 + +.. image:: http://image.iswbm.com/20211218160700.png + +然后为你的应用,创建几个 Heroku 规定的文件 + +- requirements.txt:依赖包文件 +- setup.sh:安装脚本,主要是创建文件夹,写入配置文件 +- Procfile:启动脚本,告诉 Heroku 如何安装并启动应用 + +这些文件的编程有固定的格式,我这边编写好了一份模板下载地址 +https://www.lanzout.com/ikMWkxqktgj + +.. image:: http://image.iswbm.com/20211218163524.png + +拿到了这份模板后,你就可以基于这份模板创建你的 git 仓库 + +:: + + git init + git add --all + git commit -m "init" + +然后部署到 Heroku + +:: + + heroku login + heroku create + git push heroku master + heroku ps:scale web=1 + +按照命令行输出的URL就可以访问你的应用了。 + +查看Heroku日志: + +:: + + heroku logs --tail + +要想使用自己域名,需要先通过Heroku验证。然后运行: + +:: + + heroku domains:add hivecnstats.iswbm.com + +使用 Heroku 唯一的缺点就是 Heroku +是需要梯子的,一般人访问不了,没条件的还是乖乖的备台服务器吧。 + +12. 总结一下 +------------ + +Streamlit +一个开箱即用的工具集,它可以让一个普通的个人开发者免于学习繁杂的前端知识,就可以轻松、快速的构建一个简洁、优雅的 +web app 应用,这是 streamlit 最吸引人的地方。 + +对于从事数据分析,机器学习领域的人来说,它绝对是开发神器,但即使你不是这些领域的人,你肯定也会有搭建一个 +web app 需求的时候,streamlit 正是你需要的。 From d46cabda5aaf616e72e21b7dd7d916c1721a3609 Mon Sep 17 00:00:00 2001 From: iswbm Date: 2022年2月19日 19:09:17 +0800 Subject: [PATCH 03/14] update --- source/c01/c01_01.md | 1 - source/c01/c01_01.rst | 2 - source/c01/c01_02.md | 2 +- source/c01/c01_02.rst | 2 - source/c01/c01_03.md | 2 +- source/c01/c01_03.rst | 2 - source/c01/c01_04.md | 1 - source/c01/c01_04.rst | 2 - source/c01/c01_05.md | 1 - source/c01/c01_05.rst | 2 - source/c01/c01_06.md | 1 - source/c01/c01_06.rst | 2 - source/c01/c01_07.md | 2 +- source/c01/c01_07.rst | 2 - source/c01/c01_08.md | 2 +- source/c01/c01_08.rst | 2 - source/c01/c01_09.md | 2 +- source/c01/c01_09.rst | 2 - source/c01/c01_10.md | 2 +- source/c01/c01_10.rst | 2 - source/c01/c01_11.md | 2 +- source/c01/c01_11.rst | 2 - source/c01/c01_12.md | 1 - source/c01/c01_12.rst | 2 - source/c01/c01_13.md | 1 - source/c01/c01_13.rst | 2 - source/c01/c01_14.md | 1 - source/c01/c01_14.rst | 2 - source/c01/c01_15.md | 1 - source/c01/c01_15.rst | 2 - source/c01/c01_16.md | 1 - source/c01/c01_16.rst | 2 - source/c01/c01_17.md | 2 +- source/c01/c01_17.rst | 2 - source/c01/c01_18.md | 1 - source/c01/c01_18.rst | 2 - source/c01/c01_19.md | 2 +- source/c01/c01_19.rst | 2 - source/c01/c01_20.md | 2 +- source/c01/c01_20.rst | 2 - source/c01/c01_21.md | 2 +- source/c01/c01_21.rst | 2 - source/c01/c01_22.md | 2 +- source/c01/c01_22.rst | 2 - source/c01/c01_23.md | 1 - source/c01/c01_23.rst | 2 - source/c01/c01_24.md | 1 - source/c01/c01_24.rst | 2 - source/c01/c01_25.md | 1 - source/c01/c01_25.rst | 2 - source/c01/c01_26.md | 2 +- source/c01/c01_26.rst | 2 - source/c01/c01_27.md | 1 - source/c01/c01_27.rst | 2 - source/c01/c01_28.md | 2 +- source/c01/c01_28.rst | 2 - source/c01/c01_29.md | 2 +- source/c01/c01_29.rst | 2 - source/c01/c01_30.md | 2 +- source/c01/c01_30.rst | 2 - source/c01/c01_31.md | 1 - source/c01/c01_31.rst | 2 - source/c01/c01_32.md | 1 - source/c01/c01_32.rst | 2 - source/c02/c02_01.md | 2 +- source/c02/c02_01.rst | 2 - source/c02/c02_02.md | 2 +- source/c02/c02_02.rst | 2 - source/c02/c02_03.md | 2 +- source/c02/c02_03.rst | 2 - source/c02/c02_04.md | 2 +- source/c02/c02_04.rst | 2 - source/c02/c02_05.md | 2 +- source/c02/c02_05.rst | 2 - source/c02/c02_06.md | 2 +- source/c02/c02_06.rst | 2 - source/c02/c02_07.md | 2 +- source/c02/c02_07.rst | 2 - source/c02/c02_08.md | 2 +- source/c02/c02_08.rst | 2 - source/c02/c02_09.md | 2 +- source/c02/c02_09.rst | 2 - source/c02/c02_10.md | 2 +- source/c02/c02_10.rst | 2 - source/c02/c02_11.md | 2 +- source/c02/c02_11.rst | 2 - source/c02/c02_12.md | 2 +- source/c02/c02_12.rst | 2 - source/c02/c02_13.md | 2 +- source/c02/c02_13.rst | 2 - source/c02/c02_14.md | 1 - source/c02/c02_14.rst | 2 - source/c02/c02_15.md | 1 - source/c02/c02_15.rst | 2 - source/c02/c02_16.md | 1 - source/c02/c02_16.rst | 2 - source/c02/c02_17.md | 1 - source/c02/c02_17.rst | 2 - source/c02/c02_18.md | 1 - source/c02/c02_18.rst | 2 - source/c02/c02_19.md | 1 - source/c02/c02_19.rst | 2 - source/c02/c02_20.md | 1 - source/c02/c02_20.rst | 2 - source/c02/c02_21.md | 1 - source/c02/c02_21.rst | 2 - source/c02/c02_22.md | 1 - source/c02/c02_22.rst | 2 - source/c02/c02_23.md | 1 - source/c02/c02_23.rst | 2 - source/c03/c03_01.md | 2 +- source/c03/c03_01.rst | 2 - source/c03/c03_02.md | 2 +- source/c03/c03_02.rst | 2 - source/c03/c03_03.md | 2 +- source/c03/c03_03.rst | 2 - source/c03/c03_04.md | 2 +- source/c03/c03_04.rst | 2 - source/c03/c03_05.md | 2 +- source/c03/c03_05.rst | 2 - source/c03/c03_06.md | 2 +- source/c03/c03_06.rst | 2 - source/c03/c03_07.md | 1 - source/c03/c03_07.rst | 2 - source/c03/c03_08.md | 1 - source/c03/c03_08.rst | 2 - source/c03/c03_09.md | 1 - source/c03/c03_09.rst | 2 - source/c03/c03_10.md | 1 - source/c03/c03_10.rst | 2 - source/c03/c03_11.md | 1 - source/c03/c03_11.rst | 2 - source/c03/c03_12.md | 1 - source/c03/c03_12.rst | 2 - source/c04/c04_01.md | 2 +- source/c04/c04_01.rst | 2 - source/c04/c04_02.md | 2 +- source/c04/c04_02.rst | 2 - source/c04/c04_03.md | 1 - source/c04/c04_03.rst | 2 - source/c05/c05_01.md | 2 +- source/c05/c05_01.rst | 2 - source/c05/c05_02.md | 2 +- source/c05/c05_02.rst | 2 - source/c05/c05_03.md | 2 +- source/c05/c05_03.rst | 2 - source/c05/c05_04.md | 2 +- source/c05/c05_04.rst | 2 - source/c05/c05_05.md | 2 +- source/c05/c05_05.rst | 2 - source/c05/c05_06.md | 2 +- source/c05/c05_06.rst | 2 - source/c05/c05_07.md | 2 +- source/c05/c05_07.rst | 2 - source/c05/c05_08.md | 2 +- source/c05/c05_08.rst | 2 - source/c05/c05_09.md | 2 +- source/c05/c05_09.rst | 2 - source/c05/c05_10.md | 2 +- source/c05/c05_10.rst | 2 - source/c05/c05_11.md | 2 +- source/c05/c05_11.rst | 2 - source/c05/c05_12.md | 2 +- source/c05/c05_12.rst | 2 - source/c05/c05_13.md | 2 +- source/c05/c05_13.rst | 2 - source/c05/c05_14.md | 2 +- source/c05/c05_14.rst | 2 - source/c05/c05_15.md | 2 +- source/c05/c05_15.rst | 2 - source/c05/c05_16.md | 2 +- source/c05/c05_16.rst | 2 - source/c05/c05_17.md | 2 +- source/c05/c05_17.rst | 2 - source/c05/c05_18.md | 2 +- source/c05/c05_18.rst | 2 - source/c05/c05_19.md | 2 +- source/c05/c05_19.rst | 2 - source/c05/c05_20.md | 1 - source/c05/c05_20.rst | 2 - source/c05/c05_21.md | 1 - source/c05/c05_21.rst | 2 - source/c05/c05_22.md | 1 - source/c05/c05_22.rst | 2 - source/c05/c05_23.md | 1 - source/c05/c05_23.rst | 2 - source/c05/c05_24.md | 1 - source/c05/c05_24.rst | 2 - source/c05/c05_25.md | 1 - source/c05/c05_25.rst | 2 - source/c05/c05_26.md | 1 - source/c05/c05_26.rst | 2 - source/c05/c05_27.md | 1 - source/c05/c05_27.rst | 2 - source/c05/c05_29.md | 2 +- source/c05/c05_29.rst | 2 - source/c05/c05_30.md | 1 - source/c05/c05_30.rst | 2 - source/c05/c05_31.md | 1 - source/c05/c05_31.rst | 2 - source/c05/c05_32.md | 1 - source/c05/c05_32.rst | 2 - source/c06/c06_01.md | 2 +- source/c06/c06_01.rst | 2 - source/c06/c06_02.md | 2 +- source/c06/c06_02.rst | 2 - source/c06/c06_03.md | 2 +- source/c06/c06_03.rst | 2 - source/c06/c06_04.md | 2 +- source/c06/c06_04.rst | 2 - source/c06/c06_05.md | 1 - source/c06/c06_05.rst | 2 - source/c06/c06_06.md | 1 - source/c06/c06_06.rst | 2 - source/c06/c06_07.md | 1 - source/c06/c06_07.rst | 2 - source/c06/c06_08.md | 1 - source/c06/c06_08.rst | 2 - source/c06/c06_09.md | 1 - source/c06/c06_09.rst | 2 - source/c06/c06_10.md | 1 - source/c06/c06_10.rst | 2 - source/c06/c06_11.md | 1 - source/c06/c06_11.rst | 2 - source/c06/c06_12.md | 1 - source/c06/c06_12.rst | 2 - source/c07/c07_01.md | 2 +- source/c07/c07_01.rst | 2 - source/c07/c07_02.md | 2 +- source/c07/c07_02.rst | 2 - source/c07/c07_03.md | 2 +- source/c07/c07_03.rst | 2 - source/c07/c07_04.md | 1 - source/c07/c07_04.rst | 2 - source/c07/c07_05.md | 1 - source/c07/c07_05.rst | 2 - source/c07/c07_06.md | 1 - source/c07/c07_06.rst | 2 - source/c07/c07_07.md | 1 - source/c07/c07_07.rst | 2 - source/c07/c07_08.md | 1 - source/c07/c07_08.rst | 2 - source/c07/c07_09.md | 1 - source/c07/c07_09.rst | 2 - source/c07/c07_10.md | 1 - source/c07/c07_10.rst | 2 - source/c07/c07_11.md | 1 - source/c07/c07_11.rst | 2 - source/c07/c07_12.md | 1 - source/c07/c07_12.rst | 2 - source/c07/c07_13.md | 1 - source/c07/c07_13.rst | 2 - source/c07/c07_16.md | 318 +++++++++++++++++++++++++++++++++++ source/c07/c07_16.rst | 379 ++++++++++++++++++++++++++++++++++++++++++ 254 files changed, 761 insertions(+), 378 deletions(-) create mode 100644 source/c07/c07_16.md create mode 100644 source/c07/c07_16.rst diff --git a/source/c01/c01_01.md b/source/c01/c01_01.md index 1c6a88c..51a387f 100644 --- a/source/c01/c01_01.md +++ b/source/c01/c01_01.md @@ -63,4 +63,3 @@ ok -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_01.rst b/source/c01/c01_01.rst index 7b6449e..dd37a7b 100644 --- a/source/c01/c01_01.rst +++ b/source/c01/c01_01.rst @@ -61,5 +61,3 @@ $ python3 demo.py ok - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_02.md b/source/c01/c01_02.md index d0e795e..92f5ab3 100644 --- a/source/c01/c01_02.md +++ b/source/c01/c01_02.md @@ -34,4 +34,4 @@ print(my_abs(-10)) -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_02.rst b/source/c01/c01_02.rst index 5757773..d1a3d1b 100644 --- a/source/c01/c01_02.rst +++ b/source/c01/c01_02.rst @@ -33,5 +33,3 @@ [root@localhost ~]$ python demo.py 10 10 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_03.md b/source/c01/c01_03.md index d62333e..f0d1499 100644 --- a/source/c01/c01_03.md +++ b/source/c01/c01_03.md @@ -36,4 +36,4 @@ def add(x, y): -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_03.rst b/source/c01/c01_03.rst index fd41366..46a52ca 100644 --- a/source/c01/c01_03.rst +++ b/source/c01/c01_03.rst @@ -37,5 +37,3 @@ [root@localhost ~]# python demo.zip 5 [root@localhost ~]# - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_04.md b/source/c01/c01_04.md index 996e95b..895030f 100644 --- a/source/c01/c01_04.md +++ b/source/c01/c01_04.md @@ -50,4 +50,3 @@ SyntaxError: EOL while scanning string literal -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_04.rst b/source/c01/c01_04.rst index f112b88..972c19b 100644 --- a/source/c01/c01_04.rst +++ b/source/c01/c01_04.rst @@ -47,5 +47,3 @@ str3=r"\" ^ SyntaxError: EOL while scanning string literal - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_05.md b/source/c01/c01_05.md index a6eca89..677bee4 100644 --- a/source/c01/c01_05.md +++ b/source/c01/c01_05.md @@ -33,4 +33,3 @@ Python编程时光>>>for i in range(2): -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_05.rst b/source/c01/c01_05.rst index 862929e..4971a91 100644 --- a/source/c01/c01_05.rst +++ b/source/c01/c01_05.rst @@ -32,5 +32,3 @@ ---------------- 0 1 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_06.md b/source/c01/c01_06.md index 9d7d5f8..4965e9b 100644 --- a/source/c01/c01_06.md +++ b/source/c01/c01_06.md @@ -26,4 +26,3 @@ False 这个用法叫做链式比较。 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_06.rst b/source/c01/c01_06.rst index 57951aa..846b6aa 100644 --- a/source/c01/c01_06.rst +++ b/source/c01/c01_06.rst @@ -27,5 +27,3 @@ False 这个用法叫做链式比较。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_07.md b/source/c01/c01_07.md index 2a6144c..13eb731 100644 --- a/source/c01/c01_07.md +++ b/source/c01/c01_07.md @@ -16,4 +16,4 @@ and 和 or 是我们再熟悉不过的两个逻辑运算符,在 Python 也有 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_07.rst b/source/c01/c01_07.rst index ae88d08..6802f81 100644 --- a/source/c01/c01_07.rst +++ b/source/c01/c01_07.rst @@ -15,5 +15,3 @@ and 和 or 是我们再熟悉不过的两个逻辑运算符,在 Python 也有 >>>(2 or 3) * (5 and 6 and 7) 14 # 2*7 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_08.md b/source/c01/c01_08.md index 92b2c2a..50f1da4 100644 --- a/source/c01/c01_08.md +++ b/source/c01/c01_08.md @@ -10,4 +10,4 @@ [1, 2, 3, 4, 5, 6] ``` -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_08.rst b/source/c01/c01_08.rst index da110d4..41c6116 100644 --- a/source/c01/c01_08.rst +++ b/source/c01/c01_08.rst @@ -11,5 +11,3 @@ >>> >>> sum((a,b,c), []) [1, 2, 3, 4, 5, 6] - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_09.md b/source/c01/c01_09.md index e950dc8..0546071 100644 --- a/source/c01/c01_09.md +++ b/source/c01/c01_09.md @@ -23,4 +23,4 @@ -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_09.rst b/source/c01/c01_09.rst index 0352919..2bcdd73 100644 --- a/source/c01/c01_09.rst +++ b/source/c01/c01_09.rst @@ -23,5 +23,3 @@ >>> mydict = {str(i):i for i in range(5)} >>> mydict {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4} - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_10.md b/source/c01/c01_10.md index 67588d3..b91fbfb 100644 --- a/source/c01/c01_10.md +++ b/source/c01/c01_10.md @@ -47,4 +47,4 @@ talk is cheap,show me the code. -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_10.rst b/source/c01/c01_10.rst index 9747b73..4b3df85 100644 --- a/source/c01/c01_10.rst +++ b/source/c01/c01_10.rst @@ -46,5 +46,3 @@ ... show me code.''' >>> text 'talk is cheap,\nshow me code.' - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_11.md b/source/c01/c01_11.md index 08dc826..be505b7 100644 --- a/source/c01/c01_11.md +++ b/source/c01/c01_11.md @@ -30,4 +30,4 @@ True 因为当你在同一行里,同时给两个变量赋同一值时,解释器知道这个对象已经生成,那么它就会引用到同一个对象。如果分成两行的话,解释器并不知道这个对象已经存在了,就会重新申请内存存放这个对象。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_11.rst b/source/c01/c01_11.rst index de3258b..1d5abd6 100644 --- a/source/c01/c01_11.rst +++ b/source/c01/c01_11.rst @@ -33,5 +33,3 @@ **问题又来了:最后一个示例,为啥是True?** 因为当你在同一行里,同时给两个变量赋同一值时,解释器知道这个对象已经生成,那么它就会引用到同一个对象。如果分成两行的话,解释器并不知道这个对象已经存在了,就会重新申请内存存放这个对象。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_12.md b/source/c01/c01_12.md index 0ede967..4561f96 100644 --- a/source/c01/c01_12.md +++ b/source/c01/c01_12.md @@ -41,4 +41,3 @@ False -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_12.rst b/source/c01/c01_12.rst index 421cad7..914def5 100644 --- a/source/c01/c01_12.rst +++ b/source/c01/c01_12.rst @@ -41,5 +41,3 @@ intern(字符串驻留)的技术来提高字符串效率,什么是intern >>> s2 = "ab" * 11 >>> s1 is s2 False - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_13.md b/source/c01/c01_13.md index 7c24b7c..db6637c 100644 --- a/source/c01/c01_13.md +++ b/source/c01/c01_13.md @@ -21,4 +21,3 @@ Debian 这么设计的原因,是为了减少不同来源的 Python 之间产 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_13.rst b/source/c01/c01_13.rst index 3886da0..7ff2dd7 100644 --- a/source/c01/c01_13.rst +++ b/source/c01/c01_13.rst @@ -25,5 +25,3 @@ Debian 这么设计的原因,是为了减少不同来源的 Python 之间产 >>> from distutils.sysconfig import get_python_lib >>> print(get_python_lib()) /usr/lib/python2.7/site-packages - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_14.md b/source/c01/c01_14.md index d9ee720..ac7cc49 100644 --- a/source/c01/c01_14.md +++ b/source/c01/c01_14.md @@ -19,4 +19,3 @@ output_msg("error") -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_14.rst b/source/c01/c01_14.rst index 6f4566c..587613b 100644 --- a/source/c01/c01_14.rst +++ b/source/c01/c01_14.rst @@ -21,5 +21,3 @@ arguments 和 parameter print(msg) output_msg("error") - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_15.md b/source/c01/c01_15.md index ec6b0ca..242a3e3 100644 --- a/source/c01/c01_15.md +++ b/source/c01/c01_15.md @@ -53,4 +53,3 @@ 个人感觉应该优先使用 `#!/usr/bin/env python`,因为不是所有的机器的 python 解释器都是 `/usr/bin/python` 。 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_15.rst b/source/c01/c01_15.rst index 1c0e0aa..089ad5b 100644 --- a/source/c01/c01_15.rst +++ b/source/c01/c01_15.rst @@ -63,5 +63,3 @@ 个人感觉应该优先使用 ``#!/usr/bin/env python``\ ,因为不是所有的机器的 python 解释器都是 ``/usr/bin/python`` 。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_16.md b/source/c01/c01_16.md index 8efc82a..dcf89ea 100644 --- a/source/c01/c01_16.md +++ b/source/c01/c01_16.md @@ -52,4 +52,3 @@ $ python -m dis demo.py 可以发现使用 dict(),会多了个调用函数的过程,而这个过程会有进出栈的操作,相对更加耗时。 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_16.rst b/source/c01/c01_16.rst index 4b1a960..a99e3ac 100644 --- a/source/c01/c01_16.rst +++ b/source/c01/c01_16.rst @@ -54,5 +54,3 @@ 可以发现使用 dict(),会多了个调用函数的过程,而这个过程会有进出栈的操作,相对更加耗时。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_17.md b/source/c01/c01_17.md index b74307a..5298361 100644 --- a/source/c01/c01_17.md +++ b/source/c01/c01_17.md @@ -51,4 +51,4 @@ Namespaces are one honking great idea -- let's do more of those! 就会自动打开一个网页。 ![](http://image.iswbm.com/20190511165735.png) -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_17.rst b/source/c01/c01_17.rst index beee74f..a837246 100644 --- a/source/c01/c01_17.rst +++ b/source/c01/c01_17.rst @@ -52,6 +52,4 @@ import 是 Python 导包的方式。 就会自动打开一个网页。 |image1| -.. image:: http://image.iswbm.com/20200607174235.png - .. |image1| image:: http://image.iswbm.com/20190511165735.png diff --git a/source/c01/c01_18.md b/source/c01/c01_18.md index 0d8d25a..73c5f73 100644 --- a/source/c01/c01_18.md +++ b/source/c01/c01_18.md @@ -20,4 +20,3 @@ Python 作为一门高级语言,它的编写符合人类的思维逻辑,包 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_18.rst b/source/c01/c01_18.rst index 463cbc3..f801e08 100644 --- a/source/c01/c01_18.rst +++ b/source/c01/c01_18.rst @@ -21,5 +21,3 @@ Python 作为一门高级语言,它的编写符合人类的思维逻辑,包 8 >>> 5---3 2 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_19.md b/source/c01/c01_19.md index 3c5ce5e..de36cc7 100644 --- a/source/c01/c01_19.md +++ b/source/c01/c01_19.md @@ -46,4 +46,4 @@ finally 那结论就出来了,如果 finally 里有显式的 return,那么这个 return 会直接覆盖 try 里的 return,而如果 finally 里没有 显式的 return,那么 try 里的 return 仍然有效。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_19.rst b/source/c01/c01_19.rst index b3e5e5b..fca2c69 100644 --- a/source/c01/c01_19.rst +++ b/source/c01/c01_19.rst @@ -56,5 +56,3 @@ return 真的是直接被忽视,那当finally 下没有显式的 return 那结论就出来了,如果 finally 里有显式的 return,那么这个 return 会直接覆盖 try 里的 return,而如果 finally 里没有 显式的 return,那么 try 里的 return 仍然有效。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_20.md b/source/c01/c01_20.md index b4209c2..02fbc5a 100644 --- a/source/c01/c01_20.md +++ b/source/c01/c01_20.md @@ -46,4 +46,4 @@ True -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_20.rst b/source/c01/c01_20.rst index 96486de..ace5ab2 100644 --- a/source/c01/c01_20.rst +++ b/source/c01/c01_20.rst @@ -45,5 +45,3 @@ >>> >>> "" in "M" True - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_21.md b/source/c01/c01_21.md index 81c35a6..fabdaec 100644 --- a/source/c01/c01_21.md +++ b/source/c01/c01_21.md @@ -28,4 +28,4 @@ print ("hello") 虽然 在 Python 2.6+ 可以和 Python3.x+ 一样,像函数一样去调用 print ,但是这仅用于两个 python 版本之间的代码兼容,并不是说在 python2.6+下使用 print() 后,就成了函数。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_21.rst b/source/c01/c01_21.rst index c1a86d5..7dbb290 100644 --- a/source/c01/c01_21.rst +++ b/source/c01/c01_21.rst @@ -32,5 +32,3 @@ 虽然 在 Python 2.6+ 可以和 Python3.x+ 一样,像函数一样去调用 print ,但是这仅用于两个 python 版本之间的代码兼容,并不是说在 python2.6+下使用 print() 后,就成了函数。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_22.md b/source/c01/c01_22.md index a700d70..c1ea96f 100644 --- a/source/c01/c01_22.md +++ b/source/c01/c01_22.md @@ -54,4 +54,4 @@ False 细思恐极,在这里可千万不要得罪同事们,万一离职的时候,对方把你项目里的 `e` 全局替换成 `e`,到时候你就哭去吧,肉眼根本看不出来嘛。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_22.rst b/source/c01/c01_22.rst index 2dcdf75..256f135 100644 --- a/source/c01/c01_22.rst +++ b/source/c01/c01_22.rst @@ -51,5 +51,3 @@ 细思恐极,在这里可千万不要得罪同事们,万一离职的时候,对方把你项目里的 ``e`` 全局替换成 ``e``\ ,到时候你就哭去吧,肉眼根本看不出来嘛。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_23.md b/source/c01/c01_23.md index 097f408..0a24188 100644 --- a/source/c01/c01_23.md +++ b/source/c01/c01_23.md @@ -19,4 +19,3 @@ TypeError: '<' not supported between instances of 'int' and 'str' -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_23.rst b/source/c01/c01_23.rst index 83c2cad..971bac2 100644 --- a/source/c01/c01_23.rst +++ b/source/c01/c01_23.rst @@ -18,5 +18,3 @@>>> 100000000 < "" TypeError: '<' not supported between instances of 'int' and 'str' - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_24.md b/source/c01/c01_24.md index 3715c29..9b72f04 100644 --- a/source/c01/c01_24.md +++ b/source/c01/c01_24.md @@ -24,4 +24,3 @@ IndexError: list index out of range -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_24.rst b/source/c01/c01_24.rst index 4fa42ea..012311c 100644 --- a/source/c01/c01_24.rst +++ b/source/c01/c01_24.rst @@ -24,5 +24,3 @@ []>>> alist[100:] [] - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_25.md b/source/c01/c01_25.md index 3efec97..630e061 100644 --- a/source/c01/c01_25.md +++ b/source/c01/c01_25.md @@ -56,4 +56,3 @@ True -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_25.rst b/source/c01/c01_25.rst index a6a357b..f5d0d01 100644 --- a/source/c01/c01_25.rst +++ b/source/c01/c01_25.rst @@ -55,5 +55,3 @@ True >>> 'a' * 21 is 'aaaaaaaaaaaaaaaaaaaaa' True - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_26.md b/source/c01/c01_26.md index cc9bdcc..3f2f2b0 100644 --- a/source/c01/c01_26.md +++ b/source/c01/c01_26.md @@ -32,4 +32,4 @@ Counter({'a': 3, 'b': 2}) -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_26.rst b/source/c01/c01_26.rst index 4ff81d9..0584488 100644 --- a/source/c01/c01_26.rst +++ b/source/c01/c01_26.rst @@ -32,5 +32,3 @@ >>> >>> +ct Counter({'a': 3, 'b': 2}) - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_27.md b/source/c01/c01_27.md index 14d340d..60a5378 100644 --- a/source/c01/c01_27.md +++ b/source/c01/c01_27.md @@ -28,4 +28,3 @@ -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_27.rst b/source/c01/c01_27.rst index 00a9bcc..5e9ae30 100644 --- a/source/c01/c01_27.rst +++ b/source/c01/c01_27.rst @@ -28,5 +28,3 @@ [1, 2, 3, 4, 5, 6, 7, 8] >>> b [1, 2, 3, 4, 5, 6, 7, 8] - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_28.md b/source/c01/c01_28.md index 4b1d94e..9c64c62 100644 --- a/source/c01/c01_28.md +++ b/source/c01/c01_28.md @@ -25,4 +25,4 @@ -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_28.rst b/source/c01/c01_28.rst index b5e1f46..7c8c18f 100644 --- a/source/c01/c01_28.rst +++ b/source/c01/c01_28.rst @@ -24,5 +24,3 @@ [0, 1, 2, 3, 4] >>> x 1 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_29.md b/source/c01/c01_29.md index 82fa43c..515a031 100644 --- a/source/c01/c01_29.md +++ b/source/c01/c01_29.md @@ -48,4 +48,4 @@ $ python demo.py -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_29.rst b/source/c01/c01_29.rst index a84061b..f2480ef 100644 --- a/source/c01/c01_29.rst +++ b/source/c01/c01_29.rst @@ -49,5 +49,3 @@ $ python demo.py 1 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_30.md b/source/c01/c01_30.md index 314d418..2daf0be 100644 --- a/source/c01/c01_30.md +++ b/source/c01/c01_30.md @@ -49,4 +49,4 @@ end: a = 2 1. continue 与 break 一样,如果先遇到上下文管理器会先进行资源的释放 2. 上面只举例了 while 循环体,而 for 循环也是同样的。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c01/c01_30.rst b/source/c01/c01_30.rst index 19de541..d0d0416 100644 --- a/source/c01/c01_30.rst +++ b/source/c01/c01_30.rst @@ -53,5 +53,3 @@ print 来替代)。 1. continue 与 break 一样,如果先遇到上下文管理器会先进行资源的释放 2. 上面只举例了 while 循环体,而 for 循环也是同样的。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_31.md b/source/c01/c01_31.md index 0558b61..2f6bfad 100644 --- a/source/c01/c01_31.md +++ b/source/c01/c01_31.md @@ -78,4 +78,3 @@ split函数不加参数,就能达到 awk 的效果 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_31.rst b/source/c01/c01_31.rst index eecd121..1a6af0c 100644 --- a/source/c01/c01_31.rst +++ b/source/c01/c01_31.rst @@ -80,5 +80,3 @@ split函数不加参数,就能达到 awk 的效果 >>> >>> filter(lambda item: True if item else False, msg.split('-')) ['hello', 'world'] - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c01/c01_32.md b/source/c01/c01_32.md index 59885fc..da1b08b 100644 --- a/source/c01/c01_32.md +++ b/source/c01/c01_32.md @@ -28,4 +28,3 @@ -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c01/c01_32.rst b/source/c01/c01_32.rst index cb1067f..a5ddb59 100644 --- a/source/c01/c01_32.rst +++ b/source/c01/c01_32.rst @@ -27,5 +27,3 @@ >>> number=281_028_344 >>> number 281028344 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_01.md b/source/c02/c02_01.md index 07cc0b8..012b5d8 100644 --- a/source/c02/c02_01.md +++ b/source/c02/c02_01.md @@ -62,4 +62,4 @@ world 知道这两个魔法方法的人,一看就明白了,这里不再解释啦。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_01.rst b/source/c02/c02_01.rst index 210630b..876caee 100644 --- a/source/c02/c02_01.rst +++ b/source/c02/c02_01.rst @@ -64,5 +64,3 @@ world 知道这两个魔法方法的人,一看就明白了,这里不再解释啦。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_02.md b/source/c02/c02_02.md index 39b1e70..e3c7b98 100644 --- a/source/c02/c02_02.md +++ b/source/c02/c02_02.md @@ -58,4 +58,4 @@ ENABLE_USER_SITE: True 从输出你可以发现,这个列的路径会比 sys.path 更全,它包含了用户环境的目录。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_02.rst b/source/c02/c02_02.rst index 1c6a46c..5c26789 100644 --- a/source/c02/c02_02.rst +++ b/source/c02/c02_02.rst @@ -62,5 +62,3 @@ 从输出你可以发现,这个列的路径会比 sys.path 更全,它包含了用户环境的目录。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_03.md b/source/c02/c02_03.md index 2e40d77..d486a28 100644 --- a/source/c02/c02_03.md +++ b/source/c02/c02_03.md @@ -61,4 +61,4 @@ $ python -m json.tool demo.json -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_03.rst b/source/c02/c02_03.rst index e1b103e..77c85ad 100644 --- a/source/c02/c02_03.rst +++ b/source/c02/c02_03.rst @@ -60,5 +60,3 @@ "in" ] } - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_04.md b/source/c02/c02_04.md index 0c74558..77bd821 100644 --- a/source/c02/c02_04.md +++ b/source/c02/c02_04.md @@ -15,4 +15,4 @@ $ python -c "import hashlib;print(hashlib.md5('hello').hexdigest())" 只要加 -c 参数,就可以输入你的 Python 代码了。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_04.rst b/source/c02/c02_04.rst index 1563d46..7103009 100644 --- a/source/c02/c02_04.rst +++ b/source/c02/c02_04.rst @@ -16,5 +16,3 @@ 5d41402abc4b2a76b9719d911017c592 只要加 -c 参数,就可以输入你的 Python 代码了。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_05.md b/source/c02/c02_05.md index 36dba4a..8496cdf 100644 --- a/source/c02/c02_05.md +++ b/source/c02/c02_05.md @@ -14,4 +14,4 @@ $ python -m pdb demo.py -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_05.rst b/source/c02/c02_05.rst index 9ac5a69..b829d25 100644 --- a/source/c02/c02_05.rst +++ b/source/c02/c02_05.rst @@ -14,5 +14,3 @@ > /Users/MING/demo.py(1)() -> import sys (Pdb) - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_06.md b/source/c02/c02_06.md index 7486ca4..4520f5b 100644 --- a/source/c02/c02_06.md +++ b/source/c02/c02_06.md @@ -17,4 +17,4 @@ python3 -m http.server 8888 SimpleHTTPServer有一个特性,如果待共享的目录下有index.html,那么index.html文件会被视为默认主页;如果不存在index.html文件,那么就会显示整个目录列表。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_06.rst b/source/c02/c02_06.rst index fe07dc9..8d1ade0 100644 --- a/source/c02/c02_06.rst +++ b/source/c02/c02_06.rst @@ -20,5 +20,3 @@ SimpleHTTPServer是Python .. image:: http://image.iswbm.com/20190511165716.png SimpleHTTPServer有一个特性,如果待共享的目录下有index.html,那么index.html文件会被视为默认主页;如果不存在index.html文件,那么就会显示整个目录列表。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_07.md b/source/c02/c02_07.md index b5e06e7..e03ee3d 100644 --- a/source/c02/c02_07.md +++ b/source/c02/c02_07.md @@ -24,4 +24,4 @@ pydoc server ready at http://localhost:5200/ ## -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_07.rst b/source/c02/c02_07.rst index f7b8424..ab0ae3c 100644 --- a/source/c02/c02_07.rst +++ b/source/c02/c02_07.rst @@ -24,5 +24,3 @@ 帮助文档的效果如下 .. image:: http://image.iswbm.com/20200718191249.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_08.md b/source/c02/c02_08.md index 3c145b2..79f2f46 100644 --- a/source/c02/c02_08.md +++ b/source/c02/c02_08.md @@ -29,4 +29,4 @@ $ python3.9 -m pip install requests -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_08.rst b/source/c02/c02_08.rst index da5a668..ff23b5e 100644 --- a/source/c02/c02_08.rst +++ b/source/c02/c02_08.rst @@ -31,5 +31,3 @@ Python3.9,那你安装包时就会很困惑,我到底把包安装在了哪 # 在 python3.9 中安装 $ python3.9 -m pip install requests - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_09.md b/source/c02/c02_09.md index 4b2c76f..f4f719d 100644 --- a/source/c02/c02_09.md +++ b/source/c02/c02_09.md @@ -19,4 +19,4 @@ $ python demo.py arg1 arg2 ## -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_09.rst b/source/c02/c02_09.rst index ae86a7c..03afa91 100644 --- a/source/c02/c02_09.rst +++ b/source/c02/c02_09.rst @@ -18,5 +18,3 @@ 经过我的摸索,终于找到了方法,具体方法如下: .. image:: http://image.iswbm.com/20200801195158.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_10.md b/source/c02/c02_10.md index a5f822a..4c05a0c 100644 --- a/source/c02/c02_10.md +++ b/source/c02/c02_10.md @@ -30,4 +30,4 @@ 如果希望脚本正确完成时自动退出,可以在脚本最后加上一行`__import__("os")._exit(0)` -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_10.rst b/source/c02/c02_10.rst index e4817d0..167d3e2 100644 --- a/source/c02/c02_10.rst +++ b/source/c02/c02_10.rst @@ -36,5 +36,3 @@ Shell 模式,方便你进行调试。 .. image:: http://image.iswbm.com/20200801201110.png 如果希望脚本正确完成时自动退出,可以在脚本最后加上一行\ ``__import__("os")._exit(0)`` - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_11.md b/source/c02/c02_11.md index 89acb18..e59472d 100644 --- a/source/c02/c02_11.md +++ b/source/c02/c02_11.md @@ -16,4 +16,4 @@ ![](http://image.iswbm.com/20200512125643.png) -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_11.rst b/source/c02/c02_11.rst index 6fc242d..8316a06 100644 --- a/source/c02/c02_11.rst +++ b/source/c02/c02_11.rst @@ -17,5 +17,3 @@ Python Shell,就像下面这样子,开启了极简模式,舒服多了。 .. image:: http://image.iswbm.com/20200801203047.png .. image:: http://image.iswbm.com/20200512125643.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_12.md b/source/c02/c02_12.md index 4a7e75d..d6476b2 100644 --- a/source/c02/c02_12.md +++ b/source/c02/c02_12.md @@ -50,4 +50,4 @@ 另外,有读者反馈这种设置会导致在Win10环境下 VSCode不能正常识别已安装的Python环境,并报出代码有导包错误等问题,因此请在你知道你自己在做什么,会千万什么后果,否则请在体验后还原你的环境。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_12.rst b/source/c02/c02_12.rst index 7b56f56..dbc0b44 100644 --- a/source/c02/c02_12.rst +++ b/source/c02/c02_12.rst @@ -57,5 +57,3 @@ site 模块的方法就可以获取,然后使用 ``mkdir -p`` 命令创建它 另外,有读者反馈这种设置会导致在Win10环境下 VSCode不能正常识别已安装的Python环境,并报出代码有导包错误等问题,因此请在你知道你自己在做什么,会千万什么后果,否则请在体验后还原你的环境。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_13.md b/source/c02/c02_13.md index 7af79bb..4adbfd8 100644 --- a/source/c02/c02_13.md +++ b/source/c02/c02_13.md @@ -35,4 +35,4 @@ $ export PYTHONSTARTUP=/Users/MING/startup.py ![](http://image.iswbm.com/20200801230503.png) -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c02/c02_13.rst b/source/c02/c02_13.rst index 647adaf..8dbe1e1 100644 --- a/source/c02/c02_13.rst +++ b/source/c02/c02_13.rst @@ -40,5 +40,3 @@ Shell 模式后,还是会打印平安经。 ``手动加载执行`` .. image:: http://image.iswbm.com/20200801230503.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_14.md b/source/c02/c02_14.md index b18c71b..38576ed 100644 --- a/source/c02/c02_14.md +++ b/source/c02/c02_14.md @@ -182,4 +182,3 @@ $ echo '{"name": "MING"}' | python /usr/lib64/python2.7/json/tool.py -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_14.rst b/source/c02/c02_14.rst index 07249c5..7cc5604 100644 --- a/source/c02/c02_14.rst +++ b/source/c02/c02_14.rst @@ -195,5 +195,3 @@ Python 的包导入机制会帮你做这些事情。 } 如此一对比,哪个更方便?你心里应该有数了。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_15.md b/source/c02/c02_15.md index 76ef3df..f1a1eb5 100644 --- a/source/c02/c02_15.md +++ b/source/c02/c02_15.md @@ -26,4 +26,3 @@ python3 -m idlelib unshelve.py -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_15.rst b/source/c02/c02_15.rst index 0782a8c..fb9fd17 100644 --- a/source/c02/c02_15.rst +++ b/source/c02/c02_15.rst @@ -32,5 +32,3 @@ idle,这也是为什么 idle 是大多数人的第一个 Python 代码编辑 如果你不加文件的路径,默认会打开 idle 的 shell 模式 .. image:: http://image.iswbm.com/20210504110758.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_16.md b/source/c02/c02_16.md index 023d43e..aa89ac6 100644 --- a/source/c02/c02_16.md +++ b/source/c02/c02_16.md @@ -48,4 +48,3 @@ if __name__=='__main__': -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_16.rst b/source/c02/c02_16.rst index fae57d6..ac1cbb8 100644 --- a/source/c02/c02_16.rst +++ b/source/c02/c02_16.rst @@ -48,5 +48,3 @@ 如果你的文件是 py 脚本的话,可以直接执行它 .. image:: http://image.iswbm.com/20210504112257.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_17.md b/source/c02/c02_17.md index 94fcd4a..7af31ce 100644 --- a/source/c02/c02_17.md +++ b/source/c02/c02_17.md @@ -35,4 +35,3 @@ $ python -m mimetypes sample.py.gz type: text/x-python encoding: gzip # python文件,gzip压缩 ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_17.rst b/source/c02/c02_17.rst index 0c17a17..01117bf 100644 --- a/source/c02/c02_17.rst +++ b/source/c02/c02_17.rst @@ -35,5 +35,3 @@ $ python -m mimetypes sample.py.gz type: text/x-python encoding: gzip # python文件,gzip压缩 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_18.md b/source/c02/c02_18.md index b33efe4..5a09364 100644 --- a/source/c02/c02_18.md +++ b/source/c02/c02_18.md @@ -17,4 +17,3 @@ $ python -m sysconfig ![](http://image.iswbm.com/20210504114516.png) -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_18.rst b/source/c02/c02_18.rst index a0d3d01..b8f3875 100644 --- a/source/c02/c02_18.rst +++ b/source/c02/c02_18.rst @@ -17,5 +17,3 @@ - 以及各种环境变量 .. image:: http://image.iswbm.com/20210504114516.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_19.md b/source/c02/c02_19.md index 93e941c..023d4d4 100644 --- a/source/c02/c02_19.md +++ b/source/c02/c02_19.md @@ -83,4 +83,3 @@ drwxr-xr-x 3 MING staff 96 5 4 12:57 demo -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_19.rst b/source/c02/c02_19.rst index 50041df..3642a0c 100644 --- a/source/c02/c02_19.rst +++ b/source/c02/c02_19.rst @@ -85,5 +85,3 @@ zip 格式压缩包 $ ls -l | grep demo drwxr-xr-x 3 MING staff 96 5 4 12:57 demo -rw-r--r-- 1 MING staff 74890 5 4 12:55 demo.zip - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_20.md b/source/c02/c02_20.md index 88b7200..c46c4d4 100644 --- a/source/c02/c02_20.md +++ b/source/c02/c02_20.md @@ -24,4 +24,3 @@ demo -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_20.rst b/source/c02/c02_20.rst index e68b207..f8bf1ee 100644 --- a/source/c02/c02_20.rst +++ b/source/c02/c02_20.rst @@ -24,5 +24,3 @@ pyc 文件,来提高加载速度。 ├── __pycache__ │ └── main.cpython-39.opt-1.pyc └── main.py - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_21.md b/source/c02/c02_21.md index ed5d676..770594b 100644 --- a/source/c02/c02_21.md +++ b/source/c02/c02_21.md @@ -20,4 +20,3 @@ Telnet(192.168.56.200,22): recv b'' -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_21.rst b/source/c02/c02_21.rst index 9b94aa6..6985b31 100644 --- a/source/c02/c02_21.rst +++ b/source/c02/c02_21.rst @@ -19,5 +19,3 @@ Protocol mismatch. Telnet(192.168.56.200,22): recv b'' *** Connection closed by remote host *** - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_22.md b/source/c02/c02_22.md index 9955f5a..767b8af 100644 --- a/source/c02/c02_22.md +++ b/source/c02/c02_22.md @@ -20,4 +20,3 @@ $ python3 -m zipapp demo -m "main:main" -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_22.rst b/source/c02/c02_22.rst index 394fd9d..9139902 100644 --- a/source/c02/c02_22.rst +++ b/source/c02/c02_22.rst @@ -20,5 +20,3 @@ 具体演示过程如下 .. image:: http://image.iswbm.com/20210504133711.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c02/c02_23.md b/source/c02/c02_23.md index b49369b..db473c8 100644 --- a/source/c02/c02_23.md +++ b/source/c02/c02_23.md @@ -26,4 +26,3 @@ traceback.print_stack(file=sys.stdout) /usr/lib/python2.7/site-packages/eventlet/wsgi.py(481)handle_one_response() ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c02/c02_23.rst b/source/c02/c02_23.rst index b1726ff..c073132 100644 --- a/source/c02/c02_23.rst +++ b/source/c02/c02_23.rst @@ -27,5 +27,3 @@ /usr/lib/python2.7/site-packages/eventlet/wsgi.py(384)handle_one_request() -> self.handle_one_response() /usr/lib/python2.7/site-packages/eventlet/wsgi.py(481)handle_one_response() - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_01.md b/source/c03/c03_01.md index a79dff8..034bf42 100644 --- a/source/c03/c03_01.md +++ b/source/c03/c03_01.md @@ -180,4 +180,4 @@ sorted(itertools.chain(*iterables)) -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c03/c03_01.rst b/source/c03/c03_01.rst index cca4068..9497102 100644 --- a/source/c03/c03_01.rst +++ b/source/c03/c03_01.rst @@ -189,5 +189,3 @@ heapq.merge,因为它采用堆排序,效率非常高。但若你不希望得 >>> list(merge(list01, list02, list03)) [1, 2, 3, 4, 5, 6, 7, 8, 9] >> - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_02.md b/source/c03/c03_02.md index ef80460..d350c83 100644 --- a/source/c03/c03_02.md +++ b/source/c03/c03_02.md @@ -198,4 +198,4 @@ Python 里对于生成列表、集合、字典,有一套非常 Pythonnic 的 看到这里,有没有涨姿势了,学了这么久的 Python ,没想到合并字典还有这么多的方法。本篇文章的主旨,并不在于让你全部掌握这 7 种合并字典的方法,实际在工作中,你只要选用一种最顺手的方式即可,但是在协同工作中,或者在阅读他人代码时,你不可避免地会碰到各式各样的写法,这时候你能下意识地知道这是在做合并字典的操作,那这篇文章就是有意义的。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c03/c03_02.rst b/source/c03/c03_02.rst index 14d42ad..0f72829 100644 --- a/source/c03/c03_02.rst +++ b/source/c03/c03_02.rst @@ -206,5 +206,3 @@ Operator),用它可以很直观地合并多个字典。 ,没想到合并字典还有这么多的方法。本篇文章的主旨,并不在于让你全部掌握这 7 种合并字典的方法,实际在工作中,你只要选用一种最顺手的方式即可,但是在协同工作中,或者在阅读他人代码时,你不可避免地会碰到各式各样的写法,这时候你能下意识地知道这是在做合并字典的操作,那这篇文章就是有意义的。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_03.md b/source/c03/c03_03.md index e59b4fe..3909acd 100644 --- a/source/c03/c03_03.md +++ b/source/c03/c03_03.md @@ -280,4 +280,4 @@ ok 好了,8 种方法都给大家介绍完毕,对于普通开发者来说,其实只要掌握 import 这种方法足够了,而对于那些想要自己开发框架的人来说,深入学习` __import__ `以及 importlib 是非常有必要的。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c03/c03_03.rst b/source/c03/c03_03.rst index 3e59131..a264ee1 100644 --- a/source/c03/c03_03.rst +++ b/source/c03/c03_03.rst @@ -301,5 +301,3 @@ python 文件,如果后面导入成功会打印 ``ok``\ 。 好了,8 种方法都给大家介绍完毕,对于普通开发者来说,其实只要掌握 import 这种方法足够了,而对于那些想要自己开发框架的人来说,深入学习\ ``__import__``\ 以及 importlib 是非常有必要的。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_04.md b/source/c03/c03_04.md index 721d58b..88b3906 100644 --- a/source/c03/c03_04.md +++ b/source/c03/c03_04.md @@ -145,4 +145,4 @@ else: 看到这里,有没有涨姿势了,学了这么久的 Python ,这么多骚操作,还真是活久见。。这六种写法里,我最推荐使用的是第一种,自己也经常在用,简洁直白,代码行还少。而其他的写法虽然能写,但是不会用,也不希望在我余生里碰到会在公共代码里用这些写法的同事。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c03/c03_04.rst b/source/c03/c03_04.rst index 21a3565..a14dc52 100644 --- a/source/c03/c03_04.rst +++ b/source/c03/c03_04.rst @@ -157,5 +157,3 @@ Python 功力。 看到这里,有没有涨姿势了,学了这么久的 Python ,这么多骚操作,还真是活久见。。这六种写法里,我最推荐使用的是第一种,自己也经常在用,简洁直白,代码行还少。而其他的写法虽然能写,但是不会用,也不希望在我余生里碰到会在公共代码里用这些写法的同事。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_05.md b/source/c03/c03_05.md index 7794fae..adffe2b 100644 --- a/source/c03/c03_05.md +++ b/source/c03/c03_05.md @@ -123,4 +123,4 @@ print(is_in("hello, python", "lol")) # False -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c03/c03_05.rst b/source/c03/c03_05.rst index 4cf5fc6..5944c12 100644 --- a/source/c03/c03_05.rst +++ b/source/c03/c03_05.rst @@ -129,5 +129,3 @@ python 代码快。 print(is_in("hello, python", "llo")) # True print(is_in("hello, python", "lol")) # False - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_06.md b/source/c03/c03_06.md index d210a7a..87bf9e2 100644 --- a/source/c03/c03_06.md +++ b/source/c03/c03_06.md @@ -165,4 +165,4 @@ fat_bmis = [bmi for m in members if (bmi := get_bmi(m))> 24] 海象运算符,是一个新奇的特性,有不少人觉得这样这样会破坏代码的可读性。确实在一个新鲜事物刚出来时是会这样,但我相信经过时间的沉淀后,越来越多的人使用它并享受它带来的便利时,这种争议也会慢慢消失在历史的长河中。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c03/c03_06.rst b/source/c03/c03_06.rst index 503744d..e80264d 100644 --- a/source/c03/c03_06.rst +++ b/source/c03/c03_06.rst @@ -172,5 +172,3 @@ Golang,那这里要注意,Golang 中的 ``:=`` 这里仅介绍了列表推导式,但在字典推导式和集合推导式中同样适用。不再演示。 海象运算符,是一个新奇的特性,有不少人觉得这样这样会破坏代码的可读性。确实在一个新鲜事物刚出来时是会这样,但我相信经过时间的沉淀后,越来越多的人使用它并享受它带来的便利时,这种争议也会慢慢消失在历史的长河中。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_07.md b/source/c03/c03_07.md index b750c7d..b92ccdc 100644 --- a/source/c03/c03_07.md +++ b/source/c03/c03_07.md @@ -140,4 +140,3 @@ successful to be imported -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c03/c03_07.rst b/source/c03/c03_07.rst index 06a0909..b28b751 100644 --- a/source/c03/c03_07.rst +++ b/source/c03/c03_07.rst @@ -151,5 +151,3 @@ sys.modules 来重载模块这种方法是失效的。 >>> del sys.modules['foo.bar'] >>> from foo import bar >>> - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_08.md b/source/c03/c03_08.md index f3f9f64..ee0cf0d 100644 --- a/source/c03/c03_08.md +++ b/source/c03/c03_08.md @@ -307,4 +307,3 @@ u'hello\nworld' 如果本文对你有些许帮助,不如给明哥 **来个四连** ~ 比心 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c03/c03_08.rst b/source/c03/c03_08.rst index 528ea72..7d57365 100644 --- a/source/c03/c03_08.rst +++ b/source/c03/c03_08.rst @@ -334,5 +334,3 @@ Unicode 编码其实还可以由 8 中转义的全部内容了,整理的过程,不断的发现新知识,帮助到大家的同时,自己也对转义的一些内容有了更深的理解。 如果本文对你有些许帮助,不如给明哥 **来个四连** ~ 比心 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_09.md b/source/c03/c03_09.md index 527a844..adb4399 100644 --- a/source/c03/c03_09.md +++ b/source/c03/c03_09.md @@ -121,4 +121,3 @@ $ poetry add pytest --dev $ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c03/c03_09.rst b/source/c03/c03_09.rst index b4897a4..32314f5 100644 --- a/source/c03/c03_09.rst +++ b/source/c03/c03_09.rst @@ -139,5 +139,3 @@ Python 包在使用 ``setup.py`` .. code:: shell $ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_10.md b/source/c03/c03_10.md index 05539c4..7c77708 100644 --- a/source/c03/c03_10.md +++ b/source/c03/c03_10.md @@ -323,4 +323,3 @@ class User: ![](http://image.iswbm.com/20190512113917.png) -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c03/c03_10.rst b/source/c03/c03_10.rst index c20c7d4..92bb9e9 100644 --- a/source/c03/c03_10.rst +++ b/source/c03/c03_10.rst @@ -339,5 +339,3 @@ Python工匠:使用装饰器的小技巧) 其实例化的过程,你可以参考我这里的调试过程,加以理解。 .. image:: http://image.iswbm.com/20190512113917.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_11.md b/source/c03/c03_11.md index e077467..c702b0f 100644 --- a/source/c03/c03_11.md +++ b/source/c03/c03_11.md @@ -86,4 +86,3 @@ b'hello, world' -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c03/c03_11.rst b/source/c03/c03_11.rst index 6c49d68..79cad84 100644 --- a/source/c03/c03_11.rst +++ b/source/c03/c03_11.rst @@ -93,5 +93,3 @@ os 模块也自带了 open 函数,直接操作的是底层的 I/O >>> os.read(fp, 12) b'hello, world' >>> os.close(fp) - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c03/c03_12.md b/source/c03/c03_12.md index ac144c9..fd2a6b8 100644 --- a/source/c03/c03_12.md +++ b/source/c03/c03_12.md @@ -199,4 +199,3 @@ p = People() caller(p) ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c03/c03_12.rst b/source/c03/c03_12.rst index f2e337b..49fb48f 100644 --- a/source/c03/c03_12.rst +++ b/source/c03/c03_12.rst @@ -220,5 +220,3 @@ open 来读取,最后使用 compile 函数编译运行。 caller = methodcaller("speak", "明哥") p = People() caller(p) - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c04/c04_01.md b/source/c04/c04_01.md index 7b42957..bdc9a85 100644 --- a/source/c04/c04_01.md +++ b/source/c04/c04_01.md @@ -192,4 +192,4 @@ with open_func('/Users/MING/mytest.txt') as file_in: 2. 提高代码的优雅度; 3. 提高代码的可读性; -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c04/c04_01.rst b/source/c04/c04_01.rst index c8a0531..592bb06 100644 --- a/source/c04/c04_01.rst +++ b/source/c04/c04_01.rst @@ -206,5 +206,3 @@ open)的上下文管理器。 1. 提高代码的复用率; 2. 提高代码的优雅度; 3. 提高代码的可读性; - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c04/c04_02.md b/source/c04/c04_02.md index 37227a7..ebd7b89 100644 --- a/source/c04/c04_02.md +++ b/source/c04/c04_02.md @@ -584,4 +584,4 @@ class Student: 以上便是我对描述符的全部分享,希望能对你有所帮助。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c04/c04_02.rst b/source/c04/c04_02.rst index 136f1ee..d13b7cd 100644 --- a/source/c04/c04_02.rst +++ b/source/c04/c04_02.rst @@ -638,5 +638,3 @@ instance 的。 - 之后的正确代码,则是把描述符直接当做代理,本身不存储值。 以上便是我对描述符的全部分享,希望能对你有所帮助。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c04/c04_03.md b/source/c04/c04_03.md index fab3163..5534c9c 100644 --- a/source/c04/c04_03.md +++ b/source/c04/c04_03.md @@ -350,4 +350,3 @@ in User - [Python Cookbook - 元编程](http://python3-cookbook.readthedocs.io/zh_CN/latest/chapters/p09_meta_programming.html) - [深刻理解Python中的元类](http://blog.jobbole.com/21351/) -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c04/c04_03.rst b/source/c04/c04_03.rst index 7049fdb..4d0a19e 100644 --- a/source/c04/c04_03.rst +++ b/source/c04/c04_03.rst @@ -368,5 +368,3 @@ ORM的一个类(User),就对应数据库中的一张表。id,name,email,passwo - `Python Cookbook - 元编程 `__ - `深刻理解Python中的元类 `__ - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_01.md b/source/c05/c05_01.md index 711b5e8..9a85f4b 100644 --- a/source/c05/c05_01.md +++ b/source/c05/c05_01.md @@ -38,4 +38,4 @@ with test_context('aaa'), test_context('bbb'): -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_01.rst b/source/c05/c05_01.rst index 2f3d56a..cfb02ab 100644 --- a/source/c05/c05_01.rst +++ b/source/c05/c05_01.rst @@ -37,5 +37,3 @@ with test_context('aaa'), test_context('bbb'): print('========== in main ============') - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_02.md b/source/c05/c05_02.md index af862bf..bd792b8 100644 --- a/source/c05/c05_02.md +++ b/source/c05/c05_02.md @@ -44,4 +44,4 @@ $ python demo.py -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_02.rst b/source/c05/c05_02.rst index f81118b..963c735 100644 --- a/source/c05/c05_02.rst +++ b/source/c05/c05_02.rst @@ -43,5 +43,3 @@ 14 14 15 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_03.md b/source/c05/c05_03.md index 488b8a0..e23f33a 100644 --- a/source/c05/c05_03.md +++ b/source/c05/c05_03.md @@ -35,4 +35,4 @@ for i in iter(int, 1):pass 由于int() 永远返回0,永远返回不了1,所以这个 for 循环会没有终点。一直运行下去。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_03.rst b/source/c05/c05_03.rst index fbc11c8..7c939ce 100644 --- a/source/c05/c05_03.rst +++ b/source/c05/c05_03.rst @@ -38,5 +38,3 @@ 由于int() 永远返回0,永远返回不了1,所以这个 for 循环会没有终点。一直运行下去。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_04.md b/source/c05/c05_04.md index e97d916..6ba3ce1 100644 --- a/source/c05/c05_04.md +++ b/source/c05/c05_04.md @@ -89,4 +89,4 @@ RuntimeError: Something bad happened -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_04.rst b/source/c05/c05_04.rst index 006c3ab..3b00476 100644 --- a/source/c05/c05_04.rst +++ b/source/c05/c05_04.rst @@ -87,5 +87,3 @@ raise RuntimeError("Something bad happened") from None RuntimeError: Something bad happened (PythonCodingTime) - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_05.md b/source/c05/c05_05.md index d4d68be..65fbf98 100644 --- a/source/c05/c05_05.md +++ b/source/c05/c05_05.md @@ -45,4 +45,4 @@ calculating: 2 + 3 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_05.rst b/source/c05/c05_05.rst index 613b9d8..5fe4611 100644 --- a/source/c05/c05_05.rst +++ b/source/c05/c05_05.rst @@ -46,5 +46,3 @@ 3 calculating: 2 + 3 5 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_06.md b/source/c05/c05_06.md index 288a2d5..77d56ba 100644 --- a/source/c05/c05_06.md +++ b/source/c05/c05_06.md @@ -60,4 +60,4 @@ def read_from_file(filename, block_size = 1024 * 8): -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_06.rst b/source/c05/c05_06.rst index 589942c..24760a1 100644 --- a/source/c05/c05_06.rst +++ b/source/c05/c05_06.rst @@ -67,5 +67,3 @@ with open(filename, "r") as fp: while chunk := fp.read(block_size): yield chunk - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_07.md b/source/c05/c05_07.md index 4345821..d1b00c5 100644 --- a/source/c05/c05_07.md +++ b/source/c05/c05_07.md @@ -49,4 +49,4 @@ B -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_07.rst b/source/c05/c05_07.rst index c8633a9..27b4c72 100644 --- a/source/c05/c05_07.rst +++ b/source/c05/c05_07.rst @@ -49,5 +49,3 @@ A B - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_08.md b/source/c05/c05_08.md index 5a8a786..d2a32b8 100644 --- a/source/c05/c05_08.md +++ b/source/c05/c05_08.md @@ -49,4 +49,4 @@ print(timeit.timeit(lambda :run_sleep(2), number=5)) -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_08.rst b/source/c05/c05_08.rst index 71bb7cd..604a4b5 100644 --- a/source/c05/c05_08.rst +++ b/source/c05/c05_08.rst @@ -42,5 +42,3 @@ timeit ​ 使用它,只用一行代码即可 2 2 10.020059824 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_09.md b/source/c05/c05_09.md index 7f56b4d..d2bc8b4 100644 --- a/source/c05/c05_09.md +++ b/source/c05/c05_09.md @@ -38,4 +38,4 @@ with close_stdout(): -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_09.rst b/source/c05/c05_09.rst index 28bb9c7..b67edec 100644 --- a/source/c05/c05_09.rst +++ b/source/c05/c05_09.rst @@ -38,5 +38,3 @@ with close_stdout(): you_task() - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_10.md b/source/c05/c05_10.md index a357fca..c48e524 100644 --- a/source/c05/c05_10.md +++ b/source/c05/c05_10.md @@ -25,4 +25,4 @@ -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_10.rst b/source/c05/c05_10.rst index 1fcd6f2..4ee6653 100644 --- a/source/c05/c05_10.rst +++ b/source/c05/c05_10.rst @@ -30,5 +30,3 @@ pdb 的代码。 从下图可以看出,程序执行完成后会自动进入 console 交互模式。 .. image:: http://image.iswbm.com/image-20200616000039009.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_11.md b/source/c05/c05_11.md index a3031d8..5adb138 100644 --- a/source/c05/c05_11.md +++ b/source/c05/c05_11.md @@ -19,4 +19,4 @@ - 如果发生了严重的 Python 内部错误,你注册的函数无法正常执行。 - 如果你手动调用了`os._exit()`,你注册的函数无法正常执行。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_11.rst b/source/c05/c05_11.rst index bbc500b..83ce027 100644 --- a/source/c05/c05_11.rst +++ b/source/c05/c05_11.rst @@ -21,5 +21,3 @@ - 如果程序是被你没有处理过的系统信号杀死的,那么注册的函数无法正常执行。 - 如果发生了严重的 Python 内部错误,你注册的函数无法正常执行。 - 如果你手动调用了\ ``os._exit()``\ ,你注册的函数无法正常执行。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_12.md b/source/c05/c05_12.md index e124322..e2c406b 100644 --- a/source/c05/c05_12.md +++ b/source/c05/c05_12.md @@ -44,4 +44,4 @@ for i in range(3): -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_12.rst b/source/c05/c05_12.rst index e05e8d5..6e254a9 100644 --- a/source/c05/c05_12.rst +++ b/source/c05/c05_12.rst @@ -43,5 +43,3 @@ print 的取消换行 [root@localhost ~]# python demo.py 0 1 2 [root@localhost ~]# - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_13.md b/source/c05/c05_13.md index 72330ff..096b211 100644 --- a/source/c05/c05_13.md +++ b/source/c05/c05_13.md @@ -38,4 +38,4 @@ def add(x, y): -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_13.rst b/source/c05/c05_13.rst index f400762..26dca7c 100644 --- a/source/c05/c05_13.rst +++ b/source/c05/c05_13.rst @@ -35,5 +35,3 @@ =================== def add(x, y): return x + y - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_14.md b/source/c05/c05_14.md index a54285d..3fb541a 100644 --- a/source/c05/c05_14.md +++ b/source/c05/c05_14.md @@ -158,4 +158,4 @@ hello, world -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_14.rst b/source/c05/c05_14.rst index 48036e5..b3f7b02 100644 --- a/source/c05/c05_14.rst +++ b/source/c05/c05_14.rst @@ -165,5 +165,3 @@ {'name': 'wangbm', 'age': 25} ('apple', 'huawei', 'vivo', 'oppo') 【错误】:参数类型不同,无法拼接!! - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_15.md b/source/c05/c05_15.md index c724fe3..9ce97ad 100644 --- a/source/c05/c05_15.md +++ b/source/c05/c05_15.md @@ -40,4 +40,4 @@ logout -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_15.rst b/source/c05/c05_15.rst index 3aacf37..5dab09d 100644 --- a/source/c05/c05_15.rst +++ b/source/c05/c05_15.rst @@ -40,5 +40,3 @@ # 退出 wangbm 用户,在 root 用户环境中发现 requests 未安装 [root@localhost ~]$ pip list | grep requests [root@localhost ~]$ - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_16.md b/source/c05/c05_16.md index 5c3ca24..8f9b1dd 100644 --- a/source/c05/c05_16.md +++ b/source/c05/c05_16.md @@ -68,4 +68,4 @@ b 因此在多个换行符的情况下,请务必使用 split 方法。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_16.rst b/source/c05/c05_16.rst index 52fd8ad..f9c6183 100644 --- a/source/c05/c05_16.rst +++ b/source/c05/c05_16.rst @@ -74,5 +74,3 @@ ['a\n', 'b\n'] 因此在多个换行符的情况下,请务必使用 split 方法。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_17.md b/source/c05/c05_17.md index 7dcfad8..310e5fc 100644 --- a/source/c05/c05_17.md +++ b/source/c05/c05_17.md @@ -44,4 +44,4 @@ def my_reverse(str): [3, 2, 1] ``` -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_17.rst b/source/c05/c05_17.rst index b24dcde..dab778f 100644 --- a/source/c05/c05_17.rst +++ b/source/c05/c05_17.rst @@ -45,5 +45,3 @@ 'cba' >>> ml[::-1] [3, 2, 1] - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_18.md b/source/c05/c05_18.md index ae3c685..99d0b6f 100644 --- a/source/c05/c05_18.md +++ b/source/c05/c05_18.md @@ -16,4 +16,4 @@ hello, python -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_18.rst b/source/c05/c05_18.rst index 72d6ab9..1a5d426 100644 --- a/source/c05/c05_18.rst +++ b/source/c05/c05_18.rst @@ -17,5 +17,3 @@ Python 3 中的 print $ cat test.log hello, python - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_19.md b/source/c05/c05_19.md index f05e4ac..9678ff8 100644 --- a/source/c05/c05_19.md +++ b/source/c05/c05_19.md @@ -21,4 +21,4 @@ -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_19.rst b/source/c05/c05_19.rst index 03ad9cc..98ffc71 100644 --- a/source/c05/c05_19.rst +++ b/source/c05/c05_19.rst @@ -20,5 +20,3 @@ >>> sys.setrecursionlimit(2000) >>> sys.getrecursionlimit() 2000 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_20.md b/source/c05/c05_20.md index b38c990..ccfa31a 100644 --- a/source/c05/c05_20.md +++ b/source/c05/c05_20.md @@ -62,4 +62,3 @@ test_try_else("ming") 总结一下,for else 和 try else 相同,只要代码正常走下去不被 break,不抛出异常,就可以走else。 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_20.rst b/source/c05/c05_20.rst index f9191c4..d704c74 100644 --- a/source/c05/c05_20.rst +++ b/source/c05/c05_20.rst @@ -66,5 +66,3 @@ break,还是没有break? 总结一下,for else 和 try else 相同,只要代码正常走下去不被 break,不抛出异常,就可以走else。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_21.md b/source/c05/c05_21.md index 8a652c4..2406429 100644 --- a/source/c05/c05_21.md +++ b/source/c05/c05_21.md @@ -61,4 +61,3 @@ defaultdict( at 0x10ff10488>, {}) -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_21.rst b/source/c05/c05_21.rst index 2caf116..ecd39dc 100644 --- a/source/c05/c05_21.rst +++ b/source/c05/c05_21.rst @@ -63,5 +63,3 @@ defaultdict 接收一个工厂方法,工厂方法返回的对象就是字典 >>> >>> info["msg"] 'default value' - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_22.md b/source/c05/c05_22.md index 419d0cf..c7a65cb 100644 --- a/source/c05/c05_22.md +++ b/source/c05/c05_22.md @@ -51,4 +51,3 @@ calling __call__ function >>> ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_22.rst b/source/c05/c05_22.rst index 94968b5..46655ab 100644 --- a/source/c05/c05_22.rst +++ b/source/c05/c05_22.rst @@ -53,5 +53,3 @@ >>> add(2)(3)(4)(5)(6)(7) 27 >>> - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_23.md b/source/c05/c05_23.md index 12c9359..49d8893 100644 --- a/source/c05/c05_23.md +++ b/source/c05/c05_23.md @@ -45,4 +45,3 @@ -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_23.rst b/source/c05/c05_23.rst index 50998c2..25620db 100644 --- a/source/c05/c05_23.rst +++ b/source/c05/c05_23.rst @@ -45,5 +45,3 @@ >>> students.sort(key=lambda student: (-student['score'], student['age'])) >>> students [{'age': 17, 'score': 80, 'name': 'Julia'}, {'age': 16, 'score': 80, 'name': 'Tom'}, {'age': 17, 'score': 89, 'name': 'Jack'}] - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_24.md b/source/c05/c05_24.md index fa8eb51..744da11 100644 --- a/source/c05/c05_24.md +++ b/source/c05/c05_24.md @@ -137,4 +137,3 @@ -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_24.rst b/source/c05/c05_24.rst index 6cb6c2d..7a02ae0 100644 --- a/source/c05/c05_24.rst +++ b/source/c05/c05_24.rst @@ -140,5 +140,3 @@ 08 064 0512 09 081 0729 10 100 1000 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_25.md b/source/c05/c05_25.md index 8c2a2bb..9aea66b 100644 --- a/source/c05/c05_25.md +++ b/source/c05/c05_25.md @@ -29,4 +29,3 @@ TypeError: demo_func() takes 2 positional arguments but 3 were given 3 ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_25.rst b/source/c05/c05_25.rst index 5fc0fa9..7d69846 100644 --- a/source/c05/c05_25.rst +++ b/source/c05/c05_25.rst @@ -32,5 +32,3 @@ 1 2 3 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_26.md b/source/c05/c05_26.md index 52bcf9d..e7cba1f 100644 --- a/source/c05/c05_26.md +++ b/source/c05/c05_26.md @@ -37,4 +37,3 @@ Traceback (most recent call last): TypeError: missing a required argument: 'age' ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_26.rst b/source/c05/c05_26.rst index 44738a1..70bf69f 100644 --- a/source/c05/c05_26.rst +++ b/source/c05/c05_26.rst @@ -38,5 +38,3 @@ File "/usr/lib64/python3.6/inspect.py", line 2912, in _bind raise TypeError(msg) from None TypeError: missing a required argument: 'age' - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_27.md b/source/c05/c05_27.md index 36746ec..e0cc76b 100644 --- a/source/c05/c05_27.md +++ b/source/c05/c05_27.md @@ -34,4 +34,3 @@ True -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_27.rst b/source/c05/c05_27.rst index 0fe2894..799708e 100644 --- a/source/c05/c05_27.rst +++ b/source/c05/c05_27.rst @@ -37,5 +37,3 @@ True >>> version.parse("1.3.a4") < version.parse("10.1.2") True - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_29.md b/source/c05/c05_29.md index e43ffdf..71e9bf6 100644 --- a/source/c05/c05_29.md +++ b/source/c05/c05_29.md @@ -43,4 +43,4 @@ class Sentinel(object): 140151569169808 ``` -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c05/c05_29.rst b/source/c05/c05_29.rst index 29e8c0b..b9e351a 100644 --- a/source/c05/c05_29.rst +++ b/source/c05/c05_29.rst @@ -46,5 +46,3 @@ Python 的魔法方法了。>>> new_obj = deepcopy(obj) >>> id(new_obj) 140151569169808 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_30.md b/source/c05/c05_30.md index 4748400..4fe54a7 100644 --- a/source/c05/c05_30.md +++ b/source/c05/c05_30.md @@ -43,4 +43,3 @@ def varname(*args): 附上 :[inspect 学习文档](https://docs.python.org/zh-cn/3.7/library/inspect.html) -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_30.rst b/source/c05/c05_30.rst index 08e29e6..0956f47 100644 --- a/source/c05/c05_30.rst +++ b/source/c05/c05_30.rst @@ -45,5 +45,3 @@ 附上 :\ `inspect 学习文档 `__ - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_31.md b/source/c05/c05_31.md index beb05b7..35b8bca 100644 --- a/source/c05/c05_31.md +++ b/source/c05/c05_31.md @@ -97,4 +97,3 @@ p.speak() 这种方法,最为安全,不会影响其他实例。并且 Python 2 和 Python 3 都适用,是官方推荐的一种做法。 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_31.rst b/source/c05/c05_31.rst index 2da60be..bbf1c6d 100644 --- a/source/c05/c05_31.rst +++ b/source/c05/c05_31.rst @@ -108,5 +108,3 @@ method ,你可以把替换前后的 speak 打印出来 这种方法,最为安全,不会影响其他实例。并且 Python 2 和 Python 3 都适用,是官方推荐的一种做法。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c05/c05_32.md b/source/c05/c05_32.md index 3f358d4..cf561ba 100644 --- a/source/c05/c05_32.md +++ b/source/c05/c05_32.md @@ -27,4 +27,3 @@ python -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c05/c05_32.rst b/source/c05/c05_32.rst index 521d63e..25b6902 100644 --- a/source/c05/c05_32.rst +++ b/source/c05/c05_32.rst @@ -25,5 +25,3 @@ world python - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_01.md b/source/c06/c06_01.md index dc87e8a..774c007 100644 --- a/source/c06/c06_01.md +++ b/source/c06/c06_01.md @@ -40,4 +40,4 @@ ins.call_private() ## -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c06/c06_01.rst b/source/c06/c06_01.rst index a68e842..89a2ece 100644 --- a/source/c06/c06_01.rst +++ b/source/c06/c06_01.rst @@ -39,5 +39,3 @@ # 调用私有方法,以下两种等价 ins._Kls__private() ins.call_private() - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_02.md b/source/c06/c06_02.md index 94b1dfd..316564b 100644 --- a/source/c06/c06_02.md +++ b/source/c06/c06_02.md @@ -41,4 +41,4 @@ Python 中的 def 语句在每次执行的时候都初始化一个函数对象 ## -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c06/c06_02.rst b/source/c06/c06_02.rst index 0ab9ca1..a9b4e9d 100644 --- a/source/c06/c06_02.rst +++ b/source/c06/c06_02.rst @@ -44,5 +44,3 @@ Python 中的 def 会与这个内存地址绑定。在后面的函数调用中,如果调用方指定了新的默认值,就会将原来的默认值覆盖。如果调用方没有指定新的默认值,那就会使用原来的默认值。 .. image:: http://image.iswbm.com/20190511165650.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_03.md b/source/c06/c06_03.md index 9ac278c..c6782ce 100644 --- a/source/c06/c06_03.md +++ b/source/c06/c06_03.md @@ -21,4 +21,4 @@ a = 1; a = a + 1 所以在能使用增量赋值的时候尽量使用它。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c06/c06_03.rst b/source/c06/c06_03.rst index 73aa3bf..3ec7b2e 100644 --- a/source/c06/c06_03.rst +++ b/source/c06/c06_03.rst @@ -25,5 +25,3 @@ a+b,前者是直接在原列表上进行扩展,而后者是先从原列表中取出值,在一个新的列表中进行扩展,然后再将新的列表对象返回给变量,显然后者的消耗要大些。 所以在能使用增量赋值的时候尽量使用它。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_04.md b/source/c06/c06_04.md index 46b7fb0..37fc918 100644 --- a/source/c06/c06_04.md +++ b/source/c06/c06_04.md @@ -345,4 +345,4 @@ json.dumps 的关键参数有两个: 2. 若真要使用,且有和我一样的改造需求,可以参考我的实现 3. Python 2 中的 print 语句后居然可以加 逗号 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c06/c06_04.rst b/source/c06/c06_04.rst index 4b99dcd..aff5aef 100644 --- a/source/c06/c06_04.rst +++ b/source/c06/c06_04.rst @@ -378,5 +378,3 @@ json.dumps 的关键参数有两个: 1. 核心观点:Python2 下不要再使用 pprint 2. 若真要使用,且有和我一样的改造需求,可以参考我的实现 3. Python 2 中的 print 语句后居然可以加 逗号 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_05.md b/source/c06/c06_05.md index e7ea9f0..8534101 100644 --- a/source/c06/c06_05.md +++ b/source/c06/c06_05.md @@ -72,4 +72,3 @@ SyntaxError: invalid syntax -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_05.rst b/source/c06/c06_05.rst index d42a33b..d4de33f 100644 --- a/source/c06/c06_05.rst +++ b/source/c06/c06_05.rst @@ -72,5 +72,3 @@ Python 的关键字,可以通过 keyword 这个模块列出来,一共有 33 .. code:: python >>> try_ = True - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_06.md b/source/c06/c06_06.md index b08b494..f753475 100644 --- a/source/c06/c06_06.md +++ b/source/c06/c06_06.md @@ -46,4 +46,3 @@ class Son(Parent): -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_06.rst b/source/c06/c06_06.rst index d055432..6fe86a1 100644 --- a/source/c06/c06_06.rst +++ b/source/c06/c06_06.rst @@ -48,5 +48,3 @@ Parent 验证过程如下: .. image:: http://image.iswbm.com/20200823205210.png - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_07.md b/source/c06/c06_07.md index 5e075ea..6d60d20 100644 --- a/source/c06/c06_07.md +++ b/source/c06/c06_07.md @@ -32,4 +32,3 @@ found = all(thing == other_thing for thing in things) -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_07.rst b/source/c06/c06_07.rst index 1d2094b..f02837d 100644 --- a/source/c06/c06_07.rst +++ b/source/c06/c06_07.rst @@ -33,5 +33,3 @@ found = all(thing == other_thing for thing in things) 只要有一个不满足条件,all 函数的结果就会立刻返回 False - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_08.md b/source/c06/c06_08.md index 4a705d3..37163fb 100644 --- a/source/c06/c06_08.md +++ b/source/c06/c06_08.md @@ -39,4 +39,3 @@ def process_payment(payment): -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_08.rst b/source/c06/c06_08.rst index 1bc4dc5..2e667c3 100644 --- a/source/c06/c06_08.rst +++ b/source/c06/c06_08.rst @@ -38,5 +38,3 @@ process_standard_payment(payment) else: process_international_payment(payment) - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_09.md b/source/c06/c06_09.md index 4bfd601..b5c6fdd 100644 --- a/source/c06/c06_09.md +++ b/source/c06/c06_09.md @@ -65,4 +65,3 @@ def state_attributes(self): -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_09.rst b/source/c06/c06_09.rst index b31cf6b..fbff2aa 100644 --- a/source/c06/c06_09.rst +++ b/source/c06/c06_09.rst @@ -66,5 +66,3 @@ } 这样可以缩短代码并删除不必要的变量,从而减轻了读取函数的负担。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_10.md b/source/c06/c06_10.md index 06d4360..f8c399e 100644 --- a/source/c06/c06_10.md +++ b/source/c06/c06_10.md @@ -22,4 +22,3 @@ def function(): -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_10.rst b/source/c06/c06_10.rst index 75fde65..d0d0c70 100644 --- a/source/c06/c06_10.rst +++ b/source/c06/c06_10.rst @@ -21,5 +21,3 @@ def function(): return isinstance(a, b) or issubclass(b, a) - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_11.md b/source/c06/c06_11.md index d737c2b..31d92f1 100644 --- a/source/c06/c06_11.md +++ b/source/c06/c06_11.md @@ -54,4 +54,3 @@ _start_engine() -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_11.rst b/source/c06/c06_11.rst index 9e56739..595a324 100644 --- a/source/c06/c06_11.rst +++ b/source/c06/c06_11.rst @@ -56,5 +56,3 @@ _start_engine() 甚至是,使用\ ``import tools``\ 也可以轻易突破保护限制。所以可见,"保护属性"是一种简单的隐藏机制,只有在\ ``from tools import *``\ 时,由解释器提供简单的保护,但是可以轻易突破。这种保护更多地依赖程序员的共识:不访问、修改"保护属性"。除此之外,有没有更安全的保护机制呢?有,就是下一部分讨论的私有变量。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c06/c06_12.md b/source/c06/c06_12.md index 98fe966..54f8782 100644 --- a/source/c06/c06_12.md +++ b/source/c06/c06_12.md @@ -28,4 +28,3 @@ def tag(name,*content,class_): -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c06/c06_12.rst b/source/c06/c06_12.rst index 03d974d..6b23bbd 100644 --- a/source/c06/c06_12.rst +++ b/source/c06/c06_12.rst @@ -29,5 +29,3 @@ class,这个有类别的意思,可能你也想使用它来作为变量名, def tag(name,*content,class_): pass - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_01.md b/source/c07/c07_01.md index 4bce16a..a6e79b1 100644 --- a/source/c07/c07_01.md +++ b/source/c07/c07_01.md @@ -366,4 +366,4 @@ ssh.close() 经过了一番对比,和一些实例的展示,可以看出 Paramiko 是一个专业、让人省心的 ssh 利器,个人认为 Paramiko 模块是运维人员必学模块之一,如果你恰好需要在 Python 代码中实现 ssh 到远程服务器去获取一些信息,那么我把 Paramiko 推荐给你。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c07/c07_01.rst b/source/c07/c07_01.rst index becf148..68ce529 100644 --- a/source/c07/c07_01.rst +++ b/source/c07/c07_01.rst @@ -388,5 +388,3 @@ Windows,这里就有一件好事,一件坏事了。 是一个专业、让人省心的 ssh 利器,个人认为 Paramiko 模块是运维人员必学模块之一,如果你恰好需要在 Python 代码中实现 ssh 到远程服务器去获取一些信息,那么我把 Paramiko 推荐给你。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_02.md b/source/c07/c07_02.md index a4f13d6..cf0c21c 100644 --- a/source/c07/c07_02.md +++ b/source/c07/c07_02.md @@ -249,4 +249,4 @@ if __name__ == "__main__": 以上,就是我对 `pretty_errors` 的使用体验,总的来说,这个库功能非常强大,使用效果也特别酷炫,它就跟 PEP8 规范一样,没有它是可以,但是有了它会更好一样。对于某些想自定义错误输出场景的人,`pretty_errors` 会是一个不错的解决方案,明哥把它推荐给你。 -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c07/c07_02.rst b/source/c07/c07_02.rst index ef29dff..169a707 100644 --- a/source/c07/c07_02.rst +++ b/source/c07/c07_02.rst @@ -273,5 +273,3 @@ traceback 输出都自动美化。 PEP8 规范一样,没有它是可以,但是有了它会更好一样。对于某些想自定义错误输出场景的人,\ ``pretty_errors`` 会是一个不错的解决方案,明哥把它推荐给你。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_03.md b/source/c07/c07_03.md index 06d3aef..a30b551 100644 --- a/source/c07/c07_03.md +++ b/source/c07/c07_03.md @@ -217,4 +217,4 @@ False -![](http://image.iswbm.com/20200607174235.png) + diff --git a/source/c07/c07_03.rst b/source/c07/c07_03.rst index eca9cb7..b25a790 100644 --- a/source/c07/c07_03.rst +++ b/source/c07/c07_03.rst @@ -219,5 +219,3 @@ RetryError,而不是最根本的原因。 等待重试中... 执行回调函数 False - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_04.md b/source/c07/c07_04.md index 982f7a0..ccc206c 100644 --- a/source/c07/c07_04.md +++ b/source/c07/c07_04.md @@ -306,4 +306,3 @@ parse 库在字符串解析处理场景中提供的便利,肉眼可见,上 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_04.rst b/source/c07/c07_04.rst index 50899de..7622029 100644 --- a/source/c07/c07_04.rst +++ b/source/c07/c07_04.rst @@ -355,5 +355,3 @@ parse 库在字符串解析处理场景中提供的便利,肉眼可见,上 在一些简单的场景中,使用 parse 可比使用 re 去写正则开发效率不知道高几个 level,用它写出来的代码富有美感,可读性高,后期维护起代码来一点压力也没有,推荐你使用。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_05.md b/source/c07/c07_05.md index c6d40a9..83b6706 100644 --- a/source/c07/c07_05.md +++ b/source/c07/c07_05.md @@ -275,4 +275,3 @@ numba所完成的工作就是:解析Python函数的ast语法树并加以改造 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_05.rst b/source/c07/c07_05.rst index 55bba72..28f33de 100644 --- a/source/c07/c07_05.rst +++ b/source/c07/c07_05.rst @@ -277,5 +277,3 @@ f_add就是一个动态生成的机器码函数,我们可以把它想象成C 142 numba所完成的工作就是:解析Python函数的ast语法树并加以改造,添加类型信息;将带类型信息的ast语法树通过llvmpy动态地转换为机器码函数,然后再通过和ctypes类似的技术为机器码函数创建包装函数供Python调用。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_06.md b/source/c07/c07_06.md index eb1e9f5..75668e2 100644 --- a/source/c07/c07_06.md +++ b/source/c07/c07_06.md @@ -306,4 +306,3 @@ def demo_func(): -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_06.rst b/source/c07/c07_06.rst index b6a450e..0d9e739 100644 --- a/source/c07/c07_06.rst +++ b/source/c07/c07_06.rst @@ -327,5 +327,3 @@ PySnooper 在打印对象的调试信息时,会逐个判断它是否是 Person 以上就是明哥今天给大家介绍的一款调试神器(\ ``PySnooper``\ ) 的详细使用手册,是不是觉得还不错? - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_07.md b/source/c07/c07_07.md index 6743c2d..b222650 100644 --- a/source/c07/c07_07.md +++ b/source/c07/c07_07.md @@ -406,4 +406,3 @@ fileinput 是对 open 函数的再次封装,在仅需读取数据的场景中 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_07.rst b/source/c07/c07_07.rst index 855272a..ceef415 100644 --- a/source/c07/c07_07.rst +++ b/source/c07/c07_07.rst @@ -445,5 +445,3 @@ fileinput 是对 open 函数的再次封装,在仅需读取数据的场景中 做得更专业、更人性,当然在其他有写操作的复杂场景中,fileinput 就无能为力啦,本身从 fileinput 的命名上就知道这个模块只专注于输入(读)而不是输出(写)。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_08.md b/source/c07/c07_08.md index cdf2d48..7986008 100644 --- a/source/c07/c07_08.md +++ b/source/c07/c07_08.md @@ -47,4 +47,3 @@ print(dpath.util.values(data, "/foo/bar/*")) -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_08.rst b/source/c07/c07_08.rst index b12b254..5a698d6 100644 --- a/source/c07/c07_08.rst +++ b/source/c07/c07_08.rst @@ -43,5 +43,3 @@ # output: [10, 20, [], ['red', 'buggy', 'bumpers']] 更多案例,请前往 `官方文档 `__ 查阅。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_09.md b/source/c07/c07_09.md index 98d0546..defb45f 100644 --- a/source/c07/c07_09.md +++ b/source/c07/c07_09.md @@ -23,4 +23,3 @@ >>> ``` -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_09.rst b/source/c07/c07_09.rst index 021ef1a..2ccf375 100644 --- a/source/c07/c07_09.rst +++ b/source/c07/c07_09.rst @@ -23,5 +23,3 @@ >>> linecache.getline('/etc/passwd', 10000) >>> - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_10.md b/source/c07/c07_10.md index 2e03aa4..a15df3d 100644 --- a/source/c07/c07_10.md +++ b/source/c07/c07_10.md @@ -222,4 +222,3 @@ print(myfunc.__name__) 这么棒的一个库,推荐你使用起来。 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_10.rst b/source/c07/c07_10.rst index d1c4e5d..321d478 100644 --- a/source/c07/c07_10.rst +++ b/source/c07/c07_10.rst @@ -245,5 +245,3 @@ deco 这个库,你就可以很轻松的写出一个带参数的装饰器。同时你也不用担心他会出现签名问题,这些它都为你妥善的处理好了。 这么棒的一个库,推荐你使用起来。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_11.md b/source/c07/c07_11.md index 42ba718..ddf3a76 100644 --- a/source/c07/c07_11.md +++ b/source/c07/c07_11.md @@ -68,4 +68,3 @@ $ msgfmt locale/zh_CN/LC_MESSAGES/hello.po -o locale/zh_CN/LC_MESSAGES/hello.mo -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_11.rst b/source/c07/c07_11.rst index 4c3e87f..e0361e3 100644 --- a/source/c07/c07_11.rst +++ b/source/c07/c07_11.rst @@ -72,5 +72,3 @@ gettext 是一套 GNU下的国际化工具。主要有工具: >>> zh.install() >>> _('hello world') '你好世界' - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_12.md b/source/c07/c07_12.md index 6962ed2..41ba989 100644 --- a/source/c07/c07_12.md +++ b/source/c07/c07_12.md @@ -91,4 +91,3 @@ argument参数对应的元组存放普通参数,kwargs对应的字典存放带 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_12.rst b/source/c07/c07_12.rst index fe6c265..a6c9147 100644 --- a/source/c07/c07_12.rst +++ b/source/c07/c07_12.rst @@ -90,5 +90,3 @@ Python argument参数对应的元组存放普通参数,kwargs对应的字典存放带参数名的参数。 本文来源于:公众号"未闻Code",作者:kingname - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_13.md b/source/c07/c07_13.md index 3b84503..381c299 100644 --- a/source/c07/c07_13.md +++ b/source/c07/c07_13.md @@ -245,4 +245,3 @@ SyntaxError: invalid syntax 也正是因为这样,原生字典至今还是不可替代的存在。 -![](http://image.iswbm.com/20200607174235.png) \ No newline at end of file diff --git a/source/c07/c07_13.rst b/source/c07/c07_13.rst index fc996a9..43e4986 100644 --- a/source/c07/c07_13.rst +++ b/source/c07/c07_13.rst @@ -267,5 +267,3 @@ Munch 支持序列化为 JSON 或者 YAML 格式的字符串对象 SyntaxError: invalid syntax 也正是因为这样,原生字典至今还是不可替代的存在。 - -.. image:: http://image.iswbm.com/20200607174235.png diff --git a/source/c07/c07_16.md b/source/c07/c07_16.md new file mode 100644 index 0000000..8cce9db --- /dev/null +++ b/source/c07/c07_16.md @@ -0,0 +1,318 @@ +# 7.16 划时代的 Python 包管理工具 -- PDM + +PDM 是一个新的 Python 的包管理器,也许你还未知晓它的存在,但实际上PDM 已经诞生两年,并在 2021 年发布 1.0 版本,目前最高的版本是 1.12.8。 + +在刚听到 PDM 时,我下意识认为它是 Python Development Manager,又一个和 Pipenv 和 Poetry 一样换汤不换药的虚拟环境管理工具。 + +一直到我翻到了作者的博客,才知道 PDM 的全称是 Python Development Master,比我想像的还要牛逼一个档次。 + +值得一提的是,PDM 的作者是 PyPa 成员、Pipenv 目前主要的维护者之一,最重要的是,是他是中国人,因此这是一款国人开发的工具。 + +## 1. Why PDM? + +早期的包管理器(如 Pipevn,Poetry),都是基于虚拟环境的,虚拟环境主要是为了隔离项目开发环境,但如果涉及到虚拟 环境嵌套虚拟环境,问题就难搞了,经常会出现问题。 + +PDM 得益于一个 2018 年的 PEP 提案(PEP582,Python local packages directory),完全摒弃了虚拟环境。 + +从[作者的博客](https://frostming.com/2020/02-28/pdm-introduction/)上来看,当初之所以要重复造个轮子,完全是因为 Pipenv 和 Poetry 都不够好用,正好有 PEP582 ,可以开发一个划时代的 Python 包管理工具,它就是 PDM 。 + +PDM 包含如下特性: + +- PEP 582 本地项目库目录,支持安装与运行命令,**完全不需要虚拟环境**。 +- 一个简单且相对快速的依赖解析器,特别是对于大的二进制包发布。 +- 兼容 PEP 517 的构建后端,用于构建发布包(源码格式与 wheel 格式) +- 拥有灵活且强大的插件系统(有插件系统直接就拉开一个档次) +- [PEP 621](https://www.python.org/dev/peps/pep-0621) 元数据格式 +- 像 [pnpm](https://pnpm.io/motivation#saving-disk-space-and-boosting-installation-speed) 一样的中心化安装缓存,节省磁盘空间 + +尽管 PDM 是国人开发,但考虑到国际化,官网文档是全英文的。 + +我花了整整一天,通读完文档,消化了 70% 的 PDM 用法,现将心得整理分享出来,会对你上手 PDM 有帮助。 + +关于 PDM,内容挺多的,打算分两篇文章来完整地介绍它: + +- 面向新手的入门级教程 +- 面向骨灰级选手的教程 + +本篇是第一篇,先让大家对 pdm 的基本用法有一个框架性的理解,而 pdm 真正竞争力请持续关注后续文章。 + +## 2. 安装 PDM + +PDM 的安装方法有很多种,在官网上就有 6 种,比如 pip、pipx、homebrew 等 + +在以前的文章中,我推荐过 pipx 工具,在安装那种命令行应用的包时非常好用。 + +而此时 PDM 就是一个命令行工具,因此我也推荐使用 pipx 安装,方便统一对命令行进行管理 + +执行 pipx install pdm 即可安装 + +![](http://image.iswbm.com/image-20220212200413787.png) + +PDM 只有 Python 3.7+ 的版本才能使用,使用其他的方法安装,要先保证你的 Python 版本,但使用 pipx 则不需要你去操心。 + +## 3. 初始化 PDM + +执行 pdm init 就会开始初始化,初始化的时候,会让你选择项目的一些信息 + +- 是否要上传 PyPI +- 依赖的 Python 版本 +- License 类型 +- 作者信息 +- 邮箱信息 + +我机器上有 Python 2.7 和 Python 3.10 两个版本,在初始化项目时会把机器上的所有 Python 版本都扫描出来了,会让选择项目的 Python 版本。 + +![](http://image.iswbm.com/image-20220212204609288.png) + + 完成之后,PDM 会将你的选择以 toml 格式写入 pyproject.toml 配置文件中。 + +![](http://image.iswbm.com/image-20220212204627731.png) + +## 4. PDM 用法 + +pdm 有非常多的命令,使用 `-h` 可以看到帮助菜单 + +![](http://image.iswbm.com/image-20220212204708840.png) + +### 4.1 安装包 + +和 Poetry 一样,安装使用的是 add 命令,但 pdm 的 add 比 poetry 好用,主要体现在分组,具体请关注后续文章 + +![](http://image.iswbm.com/image-20220212205148934.png) + +### 4.2 查看包 + +使用 pdm list 可以以列表形式列出当前环境已安装的包 + +![](http://image.iswbm.com/image-20220212205220953.png) + +再加个 `--graph` 就能以树状形式查看,直接依赖包和间接依赖包关系的层级一目了然 + +![](http://image.iswbm.com/image-20220212222032290.png) + +pdm list 还有两个选项: + +- `--freeze`:以 requirements.txt 的格式列出已安装的包 +- `--json`:以 json 的格式列出已安装的包,但必须与 `--graph` 同时使用 + +要查看某个包的某体详情,直接用 pdm show 即可 + +![](http://image.iswbm.com/image-20220212211203788.png) + +### 4.3 删除包 + +删除包使用的是 remove 命令 + +![](http://image.iswbm.com/image-20220212215831751.png) + +### 4.4 项目配置 + +不加任何参数,可以打印出该项目的环境配置 + +![](http://image.iswbm.com/image-20220212211303563.png) + +想要修改的话,只要加 key 和 value 做为参数即可,以修改 pypi 镜像代理为例 + +原来上面是豆瓣源,现在我要改成阿里源,只需要执行如下命令,可比 poetry 方便多啦〜 + +![](http://image.iswbm.com/image-20220212212225849.png) + +pdm config 里面有非常多的配置,想要一一搞清楚的可以去官网查阅:https://pdm.fming.dev/configuration/ + +### 4.5 运行命令 + +想要在 pdm 的环境中执行命令或者项目,可以使用 run 命令,若是执行项目时,有诸多参数,可以在 pyproject.toml 配置命令别名,具体用法,请往后看 + +![](http://image.iswbm.com/image-20220212211033303.png) + +### 4.6 查看环境 + +使用 `info` 命令,可以查看当前项目的环境信息 + +![](http://image.iswbm.com/image-20220212223811269.png) + +### 4.7 更新包 + +更新的话,简单的场景下,使用下面这两条即可 + +```bash +# 更新所有包 +pdm update + +# 更新某个包 +pdm update +``` + +复杂的场景,pdm 也都为你考虑到了,它提供了很多选项,可以根据需要使用(以下如有解释错误,请帮忙指正) + +- `--save-compatible`:项目依赖可兼容的版本 +- `--save-wildcard`:保存通配符版本(暂不明白) +- `--save-exact`:保存有指定确切版本的包 +- `--save-minimum`:保持最小版本的包 +- `--update-reuse`:尽量只更新命令行中指定的包,其依赖包能不更新则不更新 +- `--update-eager`:更新某个包顺带更新其依赖包(递归升级) +- `--prerelease`:允许提前释放(暂不明白) +- `--unconstrained`:忽略包版本的约束,可将包升级至最新版本 +- `--top`:仅更新有在 pyproject.toml 的包 +- `--dry-run`:试运行,而不去修改 lock 文件 +- `--no-sync`:只更新 lock 文件,但不更新包 + +如果你的依赖包有设置分组,还可以指定分组进行更新 + +```bash +pdm update -G security -G http +``` + +也可以指定分组更新分组里的某个包 + +```bash +pdm update -G security cryptography +``` + +再加个 `-d` 就可以再指定 dev 依赖 + +``` bash +# 更新所有的 dev 依赖 +pdm update -d + +# 更新 dev 依赖下某个分组的某个包 +pdm update -dG test pytest +``` + +同样地,也可以指定 `--prod` 或者 `--production` 升级非 dev (即生产)的包。 + +### 4.8 切换 py + +当你在初始化 pdm 项目时,就已经选定了当前的 Python 版本和可用的 Python 版本范围,后面如果想更改,可以使用 use 命令,但版本要受之前设定的版本范围约束。 + +假设允许范围是 python 3.9+,当前使用的是 python 3.10,可以直接切换过去。 + +``` +pdm use python3.9 +``` + +## 5. 命令别名 + +在 pyproject.toml 添加 `[tool.pdm.scripts]` 可以设置快捷命令别名,若项目的执行有非常多的参数,这种设定别名的方法将很有用。 + +![](http://image.iswbm.com/image-20220213001224815.png) + + `[tool.pdm.scripts]` 有两种形式 + +```toml +# 第一种 +[tool.pdm.scripts] +start = "python main.py" + +# 第一种 +[tool.pdm.scripts] +start = {cmd = "python main.py"} +``` + +但若想在参数中加注释,就必须得使用第二种方法,例如这样 + +```toml +[tool.pdm.scripts] +start = {cmd = [ + "flask", + "run", + # Important comment here about always using port 54321 + "-p", "54321" +]} +``` + +除了 cmd 之外,还有两个参数 + +一个是 shell 参数,从输出来看你应该和看出和 cmd 的区别,和 `subprocess.Popen()` with `shell=True` 差不多一个意思 + +![](http://image.iswbm.com/image-20220213003342952.png) + +一个是 env_file 参数,可以指定配置环境变量的文件 + +```toml +[tool.pdm.scripts] +start.cmd = "flask run -p 54321" +start.env_file = ".env" +``` + +如果想要把这个环境变量的文件不仅限于某个命令,而是 pdm run 全局,可以这样配置 + +```toml +[tool.pdm.scripts] +_.env_file = ".env" +``` + +加 `--list` 或者 `-l`可以查看所有设置的快捷别名 + +![](http://image.iswbm.com/image-20220213003948180.png) + +对于每一个快捷命令,都可以设置 pre 和 post 命令: + +- pre 命令:在每次快捷命令执行前会执行 +- post 命令:在每次快捷命令执行后会执行 + +```toml +[tool.pdm.scripts] +pre_compress = "{{ Run BEFORE the `compress` script }}" +compress = "tar czvf compressed.tar.gz data/" +post_compress = "{{ Run AFTER the `compress` script }}" +``` + +## 6. 自动补全 + +pdm 的命令虽多,但并不复杂,并不太需要使用自动补全,若你真的需要补全,也可以实现。 + +对于不同的 shell,自动补全的配置方式都不太一样,这个在官网上有详细的说明。 + +如果你和我一样使用的 zsh,可以参照我的配置方式。 + +![](http://image.iswbm.com/image-20220212214047051.png) + +截图中间有一步是 vim ~/.zshrc ,是将 pdm 插件配置到 zsh 中 + +``` +plugins=(git z macos extract zsh-syntax-highlighting zsh-autosuggestions pdm) +``` + +## 7. 方案兼容 + +### 其他方案迁移到 pdm + +pdm 足够好用,也足够开放,如果你当前使用的是其他的包管理器,比如 pipenv ,poetry,或者还在用最原始的 requirements.txt ,你也可以很方便的迁移到 pdm 中来: + +- 使用 pdm import -f {file} 无需初始化,直接转换 +- 执行 pdm init 或者 pdm install 的时候,会自动识别你当前的依赖情况并转换 + +### pdm 迁移到其他方案 + +同样的,你也可以当 pdm 管理的项目,导出为其他方案 + +pyproject.toml 和 pdm.lock是 pdm 的两个核心文件。 + +pdm 做为一个后起之秀,也没有忘记向前兼容,它支持: + +- 将 pyproject.toml 转成 setup.py + + ```bash + pdm export -f setuppy -o setup.py + ``` + +- 将 pdm.lock 转成 requirements.txt + + ```bash + pdm export -o requirements.txt + ``` + +## 8. 总结一下 + +花了很大的力气,终于把 PDM 的基本用法给介绍完毕,相信一定会有人会提出质疑:这就是你所谓的 **划时代的包管理器** ? + +实际上,上面仅仅是入门操作,而 PDM 的一些核心知识,考虑到篇幅有限,我将这些进阶类的内容安排在后续文章,它将包括但不仅限于: + +- PDM 的原理剖析:PEP 582 提案 +- 发布包的构建:PEP 517 提案 +- Hook 脚本的定义与使用 +- 插件管理系统与自定义插件 +- 缓存管理系统的介绍 + +这些内容是 PDM 的核心,只有理解了这些,你才能真正用好 PDM,到那时你会感慨:**为什么 Guido 还不把这样的工具收编成标准的包管理工具?** diff --git a/source/c07/c07_16.rst b/source/c07/c07_16.rst new file mode 100644 index 0000000..a0e586c --- /dev/null +++ b/source/c07/c07_16.rst @@ -0,0 +1,379 @@ +7.16 划时代的 Python 包管理工具 – PDM +===================================== + +PDM 是一个新的 Python 的包管理器,也许你还未知晓它的存在,但实际上PDM +已经诞生两年,并在 2021 年发布 1.0 版本,目前最高的版本是 1.12.8。 + +在刚听到 PDM 时,我下意识认为它是 Python Development Manager,又一个和 +Pipenv 和 Poetry 一样换汤不换药的虚拟环境管理工具。 + +一直到我翻到了作者的博客,才知道 PDM 的全称是 Python Development +Master,比我想像的还要牛逼一个档次。 + +值得一提的是,PDM 的作者是 PyPa 成员、Pipenv +目前主要的维护者之一,最重要的是,是他是中国人,因此这是一款国人开发的工具。 + +1. Why PDM? +------------ + +早期的包管理器(如 +Pipevn,Poetry),都是基于虚拟环境的,虚拟环境主要是为了隔离项目开发环境,但如果涉及到虚拟 +环境嵌套虚拟环境,问题就难搞了,经常会出现问题。 + +PDM 得益于一个 2018 年的 PEP 提案(PEP582,Python local packages +directory),完全摒弃了虚拟环境。 + +从\ `作者的博客 `__\ 上来看,当初之所以要重复造个轮子,完全是因为 +Pipenv 和 Poetry 都不够好用,正好有 PEP582 ,可以开发一个划时代的 Python +包管理工具,它就是 PDM 。 + +PDM 包含如下特性: + +- PEP 582 + 本地项目库目录,支持安装与运行命令,\ **完全不需要虚拟环境**\ 。 +- 一个简单且相对快速的依赖解析器,特别是对于大的二进制包发布。 +- 兼容 PEP 517 的构建后端,用于构建发布包(源码格式与 wheel 格式) +- 拥有灵活且强大的插件系统(有插件系统直接就拉开一个档次) +- `PEP 621 `__ 元数据格式 +- 像 + `pnpm `__ + 一样的中心化安装缓存,节省磁盘空间 + +尽管 PDM 是国人开发,但考虑到国际化,官网文档是全英文的。 + +我花了整整一天,通读完文档,消化了 70% 的 PDM +用法,现将心得整理分享出来,会对你上手 PDM 有帮助。 + +关于 PDM,内容挺多的,打算分两篇文章来完整地介绍它: + +- 面向新手的入门级教程 +- 面向骨灰级选手的教程 + +本篇是第一篇,先让大家对 pdm 的基本用法有一个框架性的理解,而 pdm +真正竞争力请持续关注后续文章。 + +2. 安装 PDM +----------- + +PDM 的安装方法有很多种,在官网上就有 6 种,比如 pip、pipx、homebrew 等 + +在以前的文章中,我推荐过 pipx 工具,在安装那种命令行应用的包时非常好用。 + +而此时 PDM 就是一个命令行工具,因此我也推荐使用 pipx +安装,方便统一对命令行进行管理 + +执行 pipx install pdm 即可安装 + +.. image:: http://image.iswbm.com/image-20220212200413787.png + +PDM 只有 Python 3.7+ 的版本才能使用,使用其他的方法安装,要先保证你的 +Python 版本,但使用 pipx 则不需要你去操心。 + +3. 初始化 PDM +------------- + +执行 pdm init 就会开始初始化,初始化的时候,会让你选择项目的一些信息 + +- 是否要上传 PyPI +- 依赖的 Python 版本 +- License 类型 +- 作者信息 +- 邮箱信息 + +我机器上有 Python 2.7 和 Python 3.10 +两个版本,在初始化项目时会把机器上的所有 Python +版本都扫描出来了,会让选择项目的 Python 版本。 + +.. image:: http://image.iswbm.com/image-20220212204609288.png + +完成之后,PDM 会将你的选择以 toml 格式写入 pyproject.toml 配置文件中。 + +.. image:: http://image.iswbm.com/image-20220212204627731.png + +4. PDM 用法 +----------- + +pdm 有非常多的命令,使用 ``-h`` 可以看到帮助菜单 + +.. image:: http://image.iswbm.com/image-20220212204708840.png + +4.1 安装包 +~~~~~~~~~~ + +和 Poetry 一样,安装使用的是 add 命令,但 pdm 的 add 比 poetry +好用,主要体现在分组,具体请关注后续文章 + +.. image:: http://image.iswbm.com/image-20220212205148934.png + +4.2 查看包 +~~~~~~~~~~ + +使用 pdm list 可以以列表形式列出当前环境已安装的包 + +.. image:: http://image.iswbm.com/image-20220212205220953.png + +再加个 ``--graph`` +就能以树状形式查看,直接依赖包和间接依赖包关系的层级一目了然 + +.. image:: http://image.iswbm.com/image-20220212222032290.png + +pdm list 还有两个选项: + +- ``--freeze``\ :以 requirements.txt 的格式列出已安装的包 +- ``--json``\ :以 json 的格式列出已安装的包,但必须与 ``--graph`` + 同时使用 + +要查看某个包的某体详情,直接用 pdm show 即可 + +.. image:: http://image.iswbm.com/image-20220212211203788.png + +4.3 删除包 +~~~~~~~~~~ + +删除包使用的是 remove 命令 + +.. image:: http://image.iswbm.com/image-20220212215831751.png + +4.4 项目配置 +~~~~~~~~~~~~ + +不加任何参数,可以打印出该项目的环境配置 + +.. image:: http://image.iswbm.com/image-20220212211303563.png + +想要修改的话,只要加 key 和 value 做为参数即可,以修改 pypi 镜像代理为例 + +原来上面是豆瓣源,现在我要改成阿里源,只需要执行如下命令,可比 poetry +方便多啦〜 + +.. image:: http://image.iswbm.com/image-20220212212225849.png + +pdm config +里面有非常多的配置,想要一一搞清楚的可以去官网查阅:https://pdm.fming.dev/configuration/ + +4.5 运行命令 +~~~~~~~~~~~~ + +想要在 pdm 的环境中执行命令或者项目,可以使用 run +命令,若是执行项目时,有诸多参数,可以在 pyproject.toml +配置命令别名,具体用法,请往后看 + +.. image:: http://image.iswbm.com/image-20220212211033303.png + +4.6 查看环境 +~~~~~~~~~~~~ + +使用 ``info`` 命令,可以查看当前项目的环境信息 + +.. image:: http://image.iswbm.com/image-20220212223811269.png + +4.7 更新包 +~~~~~~~~~~ + +更新的话,简单的场景下,使用下面这两条即可 + +.. code:: bash + + # 更新所有包 + pdm update + + # 更新某个包 + pdm update + +复杂的场景,pdm +也都为你考虑到了,它提供了很多选项,可以根据需要使用(以下如有解释错误,请帮忙指正) + +- ``--save-compatible``\ :项目依赖可兼容的版本 +- ``--save-wildcard``\ :保存通配符版本(暂不明白) +- ``--save-exact``\ :保存有指定确切版本的包 +- ``--save-minimum``\ :保持最小版本的包 +- ``--update-reuse``\ :尽量只更新命令行中指定的包,其依赖包能不更新则不更新 +- ``--update-eager``\ :更新某个包顺带更新其依赖包(递归升级) +- ``--prerelease``\ :允许提前释放(暂不明白) +- ``--unconstrained``\ :忽略包版本的约束,可将包升级至最新版本 +- ``--top``\ :仅更新有在 pyproject.toml 的包 +- ``--dry-run``\ :试运行,而不去修改 lock 文件 +- ``--no-sync``\ :只更新 lock 文件,但不更新包 + +如果你的依赖包有设置分组,还可以指定分组进行更新 + +.. code:: bash + + pdm update -G security -G http + +也可以指定分组更新分组里的某个包 + +.. code:: bash + + pdm update -G security cryptography + +再加个 ``-d`` 就可以再指定 dev 依赖 + +.. code:: bash + + # 更新所有的 dev 依赖 + pdm update -d + + # 更新 dev 依赖下某个分组的某个包 + pdm update -dG test pytest + +同样地,也可以指定 ``--prod`` 或者 ``--production`` 升级非 dev +(即生产)的包。 + +4.8 切换 py +~~~~~~~~~~~ + +当你在初始化 pdm 项目时,就已经选定了当前的 Python 版本和可用的 Python +版本范围,后面如果想更改,可以使用 use +命令,但版本要受之前设定的版本范围约束。 + +假设允许范围是 python 3.9+,当前使用的是 python 3.10,可以直接切换过去。 + +:: + + pdm use python3.9 + +5. 命令别名 +----------- + +在 pyproject.toml 添加 ``[tool.pdm.scripts]`` +可以设置快捷命令别名,若项目的执行有非常多的参数,这种设定别名的方法将很有用。 + +.. image:: http://image.iswbm.com/image-20220213001224815.png + +``[tool.pdm.scripts]`` 有两种形式 + +.. code:: toml + + # 第一种 + [tool.pdm.scripts] + start = "python main.py" + + # 第一种 + [tool.pdm.scripts] + start = {cmd = "python main.py"} + +但若想在参数中加注释,就必须得使用第二种方法,例如这样 + +.. code:: toml + + [tool.pdm.scripts] + start = {cmd = [ + "flask", + "run", + # Important comment here about always using port 54321 + "-p", "54321" + ]} + +除了 cmd 之外,还有两个参数 + +一个是 shell 参数,从输出来看你应该和看出和 cmd 的区别,和 +``subprocess.Popen()`` with ``shell=True`` 差不多一个意思 + +.. image:: http://image.iswbm.com/image-20220213003342952.png + +一个是 env_file 参数,可以指定配置环境变量的文件 + +.. code:: toml + + [tool.pdm.scripts] + start.cmd = "flask run -p 54321" + start.env_file = ".env" + +如果想要把这个环境变量的文件不仅限于某个命令,而是 pdm run +全局,可以这样配置 + +.. code:: toml + + [tool.pdm.scripts] + _.env_file = ".env" + +加 ``--list`` 或者 ``-l``\ 可以查看所有设置的快捷别名 + +.. image:: http://image.iswbm.com/image-20220213003948180.png + +对于每一个快捷命令,都可以设置 pre 和 post 命令: + +- pre 命令:在每次快捷命令执行前会执行 +- post 命令:在每次快捷命令执行后会执行 + +.. code:: toml + + [tool.pdm.scripts] + pre_compress = "{{ Run BEFORE the `compress` script }}" + compress = "tar czvf compressed.tar.gz data/" + post_compress = "{{ Run AFTER the `compress` script }}" + +6. 自动补全 +----------- + +pdm +的命令虽多,但并不复杂,并不太需要使用自动补全,若你真的需要补全,也可以实现。 + +对于不同的 +shell,自动补全的配置方式都不太一样,这个在官网上有详细的说明。 + +如果你和我一样使用的 zsh,可以参照我的配置方式。 + +.. image:: http://image.iswbm.com/image-20220212214047051.png + +截图中间有一步是 vim ~/.zshrc ,是将 pdm 插件配置到 zsh 中 + +:: + + plugins=(git z macos extract zsh-syntax-highlighting zsh-autosuggestions pdm) + +7. 方案兼容 +----------- + +其他方案迁移到 pdm +~~~~~~~~~~~~~~~~~~ + +pdm 足够好用,也足够开放,如果你当前使用的是其他的包管理器,比如 pipenv +,poetry,或者还在用最原始的 requirements.txt ,你也可以很方便的迁移到 +pdm 中来: + +- 使用 pdm import -f {file} 无需初始化,直接转换 +- 执行 pdm init 或者 pdm install + 的时候,会自动识别你当前的依赖情况并转换 + +pdm 迁移到其他方案 +~~~~~~~~~~~~~~~~~~ + +同样的,你也可以当 pdm 管理的项目,导出为其他方案 + +pyproject.toml 和 pdm.lock是 pdm 的两个核心文件。 + +pdm 做为一个后起之秀,也没有忘记向前兼容,它支持: + +- 将 pyproject.toml 转成 setup.py + + .. code:: bash + + pdm export -f setuppy -o setup.py + +- 将 pdm.lock 转成 requirements.txt + + .. code:: bash + + pdm export -o requirements.txt + +8. 总结一下 +----------- + +花了很大的力气,终于把 PDM +的基本用法给介绍完毕,相信一定会有人会提出质疑:这就是你所谓的 +**划时代的包管理器** ? + +实际上,上面仅仅是入门操作,而 PDM +的一些核心知识,考虑到篇幅有限,我将这些进阶类的内容安排在后续文章,它将包括但不仅限于: + +- PDM 的原理剖析:PEP 582 提案 +- 发布包的构建:PEP 517 提案 +- Hook 脚本的定义与使用 +- 插件管理系统与自定义插件 +- 缓存管理系统的介绍 + +这些内容是 PDM 的核心,只有理解了这些,你才能真正用好 +PDM,到那时你会感慨:\ **为什么 Guido +还不把这样的工具收编成标准的包管理工具?** From fd160ce49a83642857285f2ab05cd539ed3973df Mon Sep 17 00:00:00 2001 From: iswbm Date: 2022年2月20日 13:09:49 +0800 Subject: [PATCH 04/14] add rebuild script --- rebuild.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 rebuild.sh diff --git a/rebuild.sh b/rebuild.sh new file mode 100755 index 0000000..10883b9 --- /dev/null +++ b/rebuild.sh @@ -0,0 +1,13 @@ +cat << EOF>/usr/local/lib/python3.6/site-packages/sphinx_rtd_theme/comments.html + + + +EOF + +rm -rf build/ && sphinx-multiversion source build/html && cp -rf build/html/master/* build/html/ From 171c56cda5d910698017e3be5f01621d5737332e Mon Sep 17 00:00:00 2001 From: iswbm Date: 2022年2月20日 13:13:52 +0800 Subject: [PATCH 05/14] add github actions --- .github/workflows/deploy.yml | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..4fb0c4e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,41 @@ +name: Deploy site files + +on: + push: + branches: + - master # 只在master上push触发部署 + paths-ignore: # 下列文件的变更不触发部署,可以自行添加 + - README.md + - LICENSE + - md2rst.py + - source/conf.py + +jobs: + deploy: + runs-on: ubuntu-latest # 使用ubuntu系统镜像运行自动化脚本 + + steps: # 自动化步骤 + - uses: actions/checkout@v2 # 第一步,下载代码仓库 + + - name: Deploy to Server # 第二步,rsync推文件 + uses: AEnterprise/rsync-deploy@v1.0 # 使用别人包装好的步骤镜像 + env: + DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} # 引用配置,SSH私钥 + ARGS: -avz --delete --exclude='*.pyc' # rsync参数,排除.pyc文件 + SERVER_PORT: ${{ secrets.SSH_PORT }} # SSH端口 + FOLDER: ./ # 要推送的文件夹,路径相对于代码仓库的根目录 + SERVER_IP: ${{ secrets.SSH_HOST }} # 引用配置,服务器的host名(IP或者域名domain.com) + USERNAME: ${{ secrets.SSH_USERNAME }} # 引用配置,服务器登录名 + SERVER_DESTINATION: ${{ secrets.WORK_HOME }} # 部署到目标文件夹 + - name: Restart server # 第三步,重启服务 + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} # 下面三个配置与上一步类似 + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.DEPLOY_KEY }} + # 重启的脚本,根据自身情况做相应改动,一般要做的是migrate数据库以及重启服务器 + script: | + cd $WORK_HOME + ./rebuild.sh + env: + WORK_HOME: ${{ secrets.WORK_HOME }} From 297bd2ff0a11230502ae3f19be5e653c576a079d Mon Sep 17 00:00:00 2001 From: iswbm Date: 2022年2月20日 13:18:10 +0800 Subject: [PATCH 06/14] fix github actions --- .github/workflows/deploy.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4fb0c4e..3b3ecbd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,6 +29,8 @@ jobs: SERVER_DESTINATION: ${{ secrets.WORK_HOME }} # 部署到目标文件夹 - name: Restart server # 第三步,重启服务 uses: appleboy/ssh-action@master + env: + WORK_HOME: ${{ secrets.WORK_HOME }} with: host: ${{ secrets.SSH_HOST }} # 下面三个配置与上一步类似 username: ${{ secrets.SSH_USERNAME }} @@ -37,5 +39,4 @@ jobs: script: | cd $WORK_HOME ./rebuild.sh - env: - WORK_HOME: ${{ secrets.WORK_HOME }} + envs: WORK_HOME From be285a9381cf9234914fe5f8459a0c9ad93149b2 Mon Sep 17 00:00:00 2001 From: iswbm Date: 2022年2月20日 13:23:34 +0800 Subject: [PATCH 07/14] fix github actions --- .github/workflows/deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3b3ecbd..300d7ef 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,16 +27,16 @@ jobs: SERVER_IP: ${{ secrets.SSH_HOST }} # 引用配置,服务器的host名(IP或者域名domain.com) USERNAME: ${{ secrets.SSH_USERNAME }} # 引用配置,服务器登录名 SERVER_DESTINATION: ${{ secrets.WORK_HOME }} # 部署到目标文件夹 - - name: Restart server # 第三步,重启服务 + - name: Restart server # 第三步,重新部署服务 uses: appleboy/ssh-action@master env: WORK_HOME: ${{ secrets.WORK_HOME }} with: host: ${{ secrets.SSH_HOST }} # 下面三个配置与上一步类似 username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.DEPLOY_KEY }} - # 重启的脚本,根据自身情况做相应改动,一般要做的是migrate数据库以及重启服务器 + port: ${{ secrets.SSH_PORT }} # SSH端口 + key: ${{ secrets.DEPLOY_KEY }} # 私钥 script: | cd $WORK_HOME ./rebuild.sh - envs: WORK_HOME + envs: WORK_HOME # 要传入 script 的环境变量 From 17dd6f74798878be8ef9781638d74d88c277dd3d Mon Sep 17 00:00:00 2001 From: iswbm Date: 2022年2月20日 14:28:57 +0800 Subject: [PATCH 08/14] remove QR code image --- source/chapters/p01.rst | 2 -- source/chapters/p02.rst | 2 -- source/chapters/p03.rst | 2 -- source/chapters/p04.rst | 2 -- source/chapters/p05.rst | 2 -- source/chapters/p06.rst | 2 -- source/chapters/p07.rst | 2 -- source/index.rst | 2 -- source/preface.rst | 4 +--- source/roadmap.rst | 2 -- 10 files changed, 1 insertion(+), 21 deletions(-) diff --git a/source/chapters/p01.rst b/source/chapters/p01.rst index 75fb487..8b82079 100644 --- a/source/chapters/p01.rst +++ b/source/chapters/p01.rst @@ -15,6 +15,4 @@ ../c01/* --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/chapters/p02.rst b/source/chapters/p02.rst index dea9213..a7cfdb1 100644 --- a/source/chapters/p02.rst +++ b/source/chapters/p02.rst @@ -12,6 +12,4 @@ ../c02/* --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/chapters/p03.rst b/source/chapters/p03.rst index f3b372c..823d0e6 100644 --- a/source/chapters/p03.rst +++ b/source/chapters/p03.rst @@ -14,6 +14,4 @@ ../c03/* --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/chapters/p04.rst b/source/chapters/p04.rst index 987245c..af513c7 100644 --- a/source/chapters/p04.rst +++ b/source/chapters/p04.rst @@ -24,6 +24,4 @@ ../c04/* --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/chapters/p05.rst b/source/chapters/p05.rst index 93c3e51..971c2ce 100644 --- a/source/chapters/p05.rst +++ b/source/chapters/p05.rst @@ -14,6 +14,4 @@ ../c05/* --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/chapters/p06.rst b/source/chapters/p06.rst index 8e6ac2d..7f60824 100644 --- a/source/chapters/p06.rst +++ b/source/chapters/p06.rst @@ -14,6 +14,4 @@ ../c06/* --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/chapters/p07.rst b/source/chapters/p07.rst index 5e6535c..9256fce 100644 --- a/source/chapters/p07.rst +++ b/source/chapters/p07.rst @@ -14,6 +14,4 @@ ../c07/* --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/index.rst b/source/index.rst index a2d0783..48a55b6 100644 --- a/source/index.rst +++ b/source/index.rst @@ -18,6 +18,4 @@ Contents: aboutme roadmap --------------- -.. figure:: http://image.iswbm.com/20200607174235.png diff --git a/source/preface.rst b/source/preface.rst index 4d459b6..bbb699a 100755 --- a/source/preface.rst +++ b/source/preface.rst @@ -20,7 +20,5 @@ Python 是一门对编程新手非常友好的语言,通常花个两个月的 内容包含各种你在教材上、培训视频中无法习得的冷门知识,魔法知识,以及开发技巧,不管对于新手还是老手,我想都会有一定的帮助。 ------------------------------- - -.. figure:: http://image.iswbm.com/20200607174235.png +---------------- diff --git a/source/roadmap.rst b/source/roadmap.rst index 970211d..88695cf 100755 --- a/source/roadmap.rst +++ b/source/roadmap.rst @@ -10,6 +10,4 @@ Roadmap | 整个项目的框架完成 --------------- -.. figure:: http://image.iswbm.com/20200607174235.png From 16640354bc7126c42ef814977d18cb05e9b58f27 Mon Sep 17 00:00:00 2001 From: iswbm Date: 2022年2月20日 14:52:21 +0800 Subject: [PATCH 09/14] upgrade dependency --- poetry.lock | 608 ----------------------------------------------- pyproject.toml | 54 ----- requirements.txt | 10 +- 3 files changed, 5 insertions(+), 667 deletions(-) delete mode 100644 poetry.lock delete mode 100644 pyproject.toml diff --git a/poetry.lock b/poetry.lock deleted file mode 100644 index 8ed3b0c..0000000 --- a/poetry.lock +++ /dev/null @@ -1,608 +0,0 @@ -[[package]] -name = "alabaster" -version = "0.7.12" -description = "A configurable sidebar-enabled Sphinx theme" -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "argh" -version = "0.26.2" -description = "An unobtrusive argparse wrapper with natural syntax" -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "babel" -version = "2.7.0" -description = "Internationalization utilities" -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" - -[package.dependencies] -pytz = ">=2015.7" - -[[package]] -name = "certifi" -version = "2019.6.16" -description = "Python package for providing Mozilla's CA Bundle." -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "chardet" -version = "3.0.4" -description = "Universal encoding detector for Python 2 and 3" -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "colorama" -version = "0.4.4" -description = "Cross-platform colored terminal text." -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[[package]] -name = "docutils" -version = "0.14" -description = "Docutils -- Python Documentation Utilities" -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "idna" -version = "2.8" -description = "Internationalized Domain Names in Applications (IDNA)" -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" - -[[package]] -name = "imagesize" -version = "1.1.0" -description = "Getting image size from png/jpeg/jpeg2000/gif file" -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" - -[[package]] -name = "jinja2" -version = "2.10.1" -description = "A small but fast and easy to use stand-alone template engine written in pure python." -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -MarkupSafe = ">=0.23" - -[package.extras] -i18n = ["Babel (>=0.8)"] - -[[package]] -name = "livereload" -version = "2.6.1" -description = "Python LiveReload is an awesome tool for web developers" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -six = "*" -tornado = "*" - -[[package]] -name = "markupsafe" -version = "1.1.1" -description = "Safely add untrusted strings to HTML/XML markup." -category = "main" -optional = false -python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" - -[[package]] -name = "packaging" -version = "19.0" -description = "Core utilities for Python packages" -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" - -[package.dependencies] -pyparsing = ">=2.0.2" -six = "*" - -[[package]] -name = "pathtools" -version = "0.1.2" -description = "File system general utilities" -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "port-for" -version = "0.3.1" -description = "Utility that helps with local TCP ports managment. It can find an unused TCP localhost port and remember the association." -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "pygments" -version = "2.4.2" -description = "Pygments is a syntax highlighting package written in Python." -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[[package]] -name = "pyparsing" -version = "2.4.0" -description = "Python parsing module" -category = "main" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" - -[[package]] -name = "pytz" -version = "2019.1" -description = "World timezone definitions, modern and historical" -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "pyyaml" -version = "5.1.1" -description = "YAML parser and emitter for Python" -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" - -[[package]] -name = "requests" -version = "2.22.0" -description = "Python HTTP for Humans." -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" - -[package.dependencies] -certifi = ">=2017年4月17日" -chardet = ">=3.0.2,<3.1.0" -idna = ">=2.5,<2.9" -urllib3 = ">=1.21.1,<1.25.0 ||>1.25.0,<1.25.1 ||>1.25.1,<1.26" - -[package.extras] -security = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)"] -socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"] - -[[package]] -name = "six" -version = "1.12.0" -description = "Python 2 and 3 compatibility utilities" -category = "main" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*" - -[[package]] -name = "snowballstemmer" -version = "1.9.0" -description = "This package provides 23 stemmers for 22 languages generated from Snowball algorithms." -category = "main" -optional = false -python-versions = "*" - -[[package]] -name = "sphinx" -version = "2.1.2" -description = "Python documentation generator" -category = "main" -optional = false -python-versions = ">=3.5" - -[package.dependencies] -alabaster = ">=0.7,<0.8" -babel = ">=1.3,<2.0 ||>2.0" -colorama = {version = ">=0.3.5", markers = "sys_platform == \"win32\""} -docutils = ">=0.12" -imagesize = "*" -Jinja2 = ">=2.3" -packaging = "*" -Pygments = ">=2.0" -requests = ">=2.5.0" -snowballstemmer = ">=1.1" -sphinxcontrib-applehelp = "*" -sphinxcontrib-devhelp = "*" -sphinxcontrib-htmlhelp = "*" -sphinxcontrib-jsmath = "*" -sphinxcontrib-qthelp = "*" -sphinxcontrib-serializinghtml = "*" - -[package.extras] -docs = ["sphinxcontrib-websupport"] -test = ["pytest", "pytest-cov", "html5lib", "flake8 (>=3.5.0)", "flake8-import-order", "mypy (>=0.590)", "docutils-stubs"] - -[[package]] -name = "sphinx-autobuild" -version = "0.7.1" -description = "Watch a Sphinx directory and rebuild the documentation when a change is detected. Also includes a livereload enabled web server." -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -argh = ">=0.24.1" -livereload = ">=2.3.0" -pathtools = ">=0.1.2" -port-for = "0.3.1" -PyYAML = ">=3.10" -tornado = ">=3.2" -watchdog = ">=0.7.1" - -[[package]] -name = "sphinx-multiversion" -version = "0.2.4" -description = "Add support for multiple versions to sphinx" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -sphinx = ">=2.1" - -[[package]] -name = "sphinx-rtd-theme" -version = "0.4.3" -description = "Read the Docs theme for Sphinx" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -sphinx = "*" - -[[package]] -name = "sphinx-sitemap" -version = "2.2.0" -description = "Sitemap generator for Sphinx" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -six = "*" -sphinx = ">=1.2" - -[[package]] -name = "sphinxcontrib-applehelp" -version = "1.0.1" -description = "" -category = "main" -optional = false -python-versions = "*" - -[package.extras] -test = ["pytest", "flake8", "mypy"] - -[[package]] -name = "sphinxcontrib-devhelp" -version = "1.0.1" -description = "" -category = "main" -optional = false -python-versions = "*" - -[package.extras] -test = ["pytest", "flake8", "mypy"] - -[[package]] -name = "sphinxcontrib-disqus" -version = "1.1.0" -description = "Sphinx extension that embeds Disqus comments in documents." -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -sphinx = "*" - -[[package]] -name = "sphinxcontrib-htmlhelp" -version = "1.0.2" -description = "" -category = "main" -optional = false -python-versions = "*" - -[package.extras] -test = ["pytest", "flake8", "mypy", "html5lib"] - -[[package]] -name = "sphinxcontrib-jsmath" -version = "1.0.1" -description = "A sphinx extension which renders display math in HTML via JavaScript" -category = "main" -optional = false -python-versions = ">=3.5" - -[package.extras] -test = ["pytest", "flake8", "mypy"] - -[[package]] -name = "sphinxcontrib-qthelp" -version = "1.0.2" -description = "" -category = "main" -optional = false -python-versions = "*" - -[package.extras] -test = ["pytest", "flake8", "mypy"] - -[[package]] -name = "sphinxcontrib-serializinghtml" -version = "1.1.3" -description = "" -category = "main" -optional = false -python-versions = "*" - -[package.extras] -test = ["pytest", "flake8", "mypy"] - -[[package]] -name = "tornado" -version = "6.0.3" -description = "Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed." -category = "main" -optional = false -python-versions = ">= 3.5" - -[[package]] -name = "urllib3" -version = "1.25.3" -description = "HTTP library with thread-safe connection pooling, file post, and more." -category = "main" -optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4" - -[package.extras] -brotli = ["brotlipy (>=0.6.0)"] -secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"] -socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] - -[[package]] -name = "watchdog" -version = "0.9.0" -description = "Filesystem events monitoring" -category = "main" -optional = false -python-versions = "*" - -[package.dependencies] -argh = ">=0.24.1" -pathtools = ">=0.1.1" -PyYAML = ">=3.10" - -[metadata] -lock-version = "1.1" -python-versions = "^3.8" -content-hash = "b74ce6a464b7eaec8de696d534565e1d344627e584b521f78fc2867fef4da910" - -[metadata.files] -alabaster = [ - {file = "alabaster-0.7.12-py2.py3-none-any.whl", hash = "sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359"}, - {file = "alabaster-0.7.12.tar.gz", hash = "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"}, -] -argh = [ - {file = "argh-0.26.2-py2.py3-none-any.whl", hash = "sha256:a9b3aaa1904eeb78e32394cd46c6f37ac0fb4af6dc488daa58971bdc7d7fcaf3"}, - {file = "argh-0.26.2.tar.gz", hash = "sha256:e9535b8c84dc9571a48999094fda7f33e63c3f1b74f3e5f3ac0105a58405bb65"}, -] -babel = [ - {file = "Babel-2.7.0-py2.py3-none-any.whl", hash = "sha256:af92e6106cb7c55286b25b38ad7695f8b4efb36a90ba483d7f7a6628c46158ab"}, - {file = "Babel-2.7.0.tar.gz", hash = "sha256:e86135ae101e31e2c8ec20a4e0c5220f4eed12487d5cf3f78be7e98d3a57fc28"}, -] -certifi = [ - {file = "certifi-2019年6月16日-py2.py3-none-any.whl", hash = "sha256:046832c04d4e752f37383b628bc601a7ea7211496b4638f6514d0e5b9acc4939"}, - {file = "certifi-2019年6月16日.tar.gz", hash = "sha256:945e3ba63a0b9f577b1395204e13c3a231f9bc0223888be653286534e5873695"}, -] -chardet = [ - {file = "chardet-3.0.4-py2.py3-none-any.whl", hash = "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"}, - {file = "chardet-3.0.4.tar.gz", hash = "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae"}, -] -colorama = [ - {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, - {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, -] -docutils = [ - {file = "docutils-0.14-py2-none-any.whl", hash = "sha256:7a4bd47eaf6596e1295ecb11361139febe29b084a87bf005bf899f9a42edc3c6"}, - {file = "docutils-0.14-py3-none-any.whl", hash = "sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6"}, - {file = "docutils-0.14.tar.gz", hash = "sha256:51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274"}, -] -idna = [ - {file = "idna-2.8-py2.py3-none-any.whl", hash = "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"}, - {file = "idna-2.8.tar.gz", hash = "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407"}, -] -imagesize = [ - {file = "imagesize-1.1.0-py2.py3-none-any.whl", hash = "sha256:3f349de3eb99145973fefb7dbe38554414e5c30abd0c8e4b970a7c9d09f3a1d8"}, - {file = "imagesize-1.1.0.tar.gz", hash = "sha256:f3832918bc3c66617f92e35f5d70729187676313caa60c187eb0f28b8fe5e3b5"}, -] -jinja2 = [ - {file = "Jinja2-2.10.1-py2.py3-none-any.whl", hash = "sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b"}, - {file = "Jinja2-2.10.1.tar.gz", hash = "sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013"}, -] -livereload = [ - {file = "livereload-2.6.1-py2.py3-none-any.whl", hash = "sha256:78d55f2c268a8823ba499305dcac64e28ddeb9a92571e12d543cd304faf5817b"}, - {file = "livereload-2.6.1.tar.gz", hash = "sha256:89254f78d7529d7ea0a3417d224c34287ebfe266b05e67e51facaf82c27f0f66"}, -] -markupsafe = [ - {file = "MarkupSafe-1.1.1-cp27-cp27m-macosx_10_6_intel.whl", hash = "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161"}, - {file = "MarkupSafe-1.1.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7"}, - {file = "MarkupSafe-1.1.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183"}, - {file = "MarkupSafe-1.1.1-cp27-cp27m-win32.whl", hash = "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b"}, - {file = "MarkupSafe-1.1.1-cp27-cp27m-win_amd64.whl", hash = "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e"}, - {file = "MarkupSafe-1.1.1-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f"}, - {file = "MarkupSafe-1.1.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1"}, - {file = "MarkupSafe-1.1.1-cp34-cp34m-macosx_10_6_intel.whl", hash = "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5"}, - {file = "MarkupSafe-1.1.1-cp34-cp34m-manylinux1_i686.whl", hash = "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1"}, - {file = "MarkupSafe-1.1.1-cp34-cp34m-manylinux1_x86_64.whl", hash = "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735"}, - {file = "MarkupSafe-1.1.1-cp34-cp34m-win32.whl", hash = "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21"}, - {file = "MarkupSafe-1.1.1-cp34-cp34m-win_amd64.whl", hash = "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235"}, - {file = "MarkupSafe-1.1.1-cp35-cp35m-macosx_10_6_intel.whl", hash = "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b"}, - {file = "MarkupSafe-1.1.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f"}, - {file = "MarkupSafe-1.1.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905"}, - {file = "MarkupSafe-1.1.1-cp35-cp35m-win32.whl", hash = "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1"}, - {file = "MarkupSafe-1.1.1-cp35-cp35m-win_amd64.whl", hash = "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_6_intel.whl", hash = "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:d53bc011414228441014aa71dbec320c66468c1030aae3a6e29778a3382d96e5"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:3b8a6499709d29c2e2399569d96719a1b21dcd94410a586a18526b143ec8470f"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:84dee80c15f1b560d55bcfe6d47b27d070b4681c699c572af2e3c7cc90a3b8e0"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:b1dba4527182c95a0db8b6060cc98ac49b9e2f5e64320e2b56e47cb2831978c7"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-win32.whl", hash = "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66"}, - {file = "MarkupSafe-1.1.1-cp36-cp36m-win_amd64.whl", hash = "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_6_intel.whl", hash = "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:bf5aa3cbcfdf57fa2ee9cd1822c862ef23037f5c832ad09cfea57fa846dec193"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:6fffc775d90dcc9aed1b89219549b329a9250d918fd0b8fa8d93d154918422e1"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:a6a744282b7718a2a62d2ed9d993cad6f5f585605ad352c11de459f4108df0a1"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:195d7d2c4fbb0ee8139a6cf67194f3973a6b3042d742ebe0a9ed36d8b6f0c07f"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2"}, - {file = "MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:acf08ac40292838b3cbbb06cfe9b2cb9ec78fce8baca31ddb87aaac2e2dc3bc2"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:d9be0ba6c527163cbed5e0857c451fcd092ce83947944d6c14bc95441203f032"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:caabedc8323f1e93231b52fc32bdcde6db817623d33e100708d9a68e1f53b26b"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-win32.whl", hash = "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b"}, - {file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:d73a845f227b0bfe8a7455ee623525ee656a9e2e749e4742706d80a6065d5e2c"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_i686.whl", hash = "sha256:98bae9582248d6cf62321dcb52aaf5d9adf0bad3b40582925ef7c7f0ed85fceb"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:2beec1e0de6924ea551859edb9e7679da6e4870d32cb766240ce17e0a0ba2014"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_i686.whl", hash = "sha256:7fed13866cf14bba33e7176717346713881f56d9d2bcebab207f7a036f41b850"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:6f1e273a344928347c1290119b493a1f0303c52f5a5eae5f16d74f48c15d4a85"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:feb7b34d6325451ef96bc0e36e1a6c0c1c64bc1fbec4b854f4529e51887b1621"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-win32.whl", hash = "sha256:22c178a091fc6630d0d045bdb5992d2dfe14e3259760e713c490da5323866c39"}, - {file = "MarkupSafe-1.1.1-cp39-cp39-win_amd64.whl", hash = "sha256:b7d644ddb4dbd407d31ffb699f1d140bc35478da613b441c582aeb7c43838dd8"}, - {file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"}, -] -packaging = [ - {file = "packaging-19.0-py2.py3-none-any.whl", hash = "sha256:9e1cbf8c12b1f1ce0bb5344b8d7ecf66a6f8a6e91bcb0c84593ed6d3ab5c4ab3"}, - {file = "packaging-19.0.tar.gz", hash = "sha256:0c98a5d0be38ed775798ece1b9727178c4469d9c3b4ada66e8e6b7849f8732af"}, -] -pathtools = [ - {file = "pathtools-0.1.2.tar.gz", hash = "sha256:7c35c5421a39bb82e58018febd90e3b6e5db34c5443aaaf742b3f33d4655f1c0"}, -] -port-for = [ - {file = "port-for-0.3.1.tar.gz", hash = "sha256:b16a84bb29c2954db44c29be38b17c659c9c27e33918dec16b90d375cc596f1c"}, -] -pygments = [ - {file = "Pygments-2.4.2-py2.py3-none-any.whl", hash = "sha256:71e430bc85c88a430f000ac1d9b331d2407f681d6f6aec95e8bcfbc3df5b0127"}, - {file = "Pygments-2.4.2.tar.gz", hash = "sha256:881c4c157e45f30af185c1ffe8d549d48ac9127433f2c380c24b84572ad66297"}, -] -pyparsing = [ - {file = "pyparsing-2.4.0-py2.py3-none-any.whl", hash = "sha256:9b6323ef4ab914af344ba97510e966d64ba91055d6b9afa6b30799340e89cc03"}, - {file = "pyparsing-2.4.0.tar.gz", hash = "sha256:1873c03321fc118f4e9746baf201ff990ceb915f433f23b395f5580d1840cb2a"}, -] -pytz = [ - {file = "pytz-2019.1-py2.py3-none-any.whl", hash = "sha256:303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda"}, - {file = "pytz-2019.1.tar.gz", hash = "sha256:d747dd3d23d77ef44c6a3526e274af6efeb0a6f1afd5a69ba4d5be4098c8e141"}, -] -pyyaml = [ - {file = "PyYAML-5.1.1-cp27-cp27m-win32.whl", hash = "sha256:70d9818f1c9cd5c48bb87804f2efc8692f1023dac7f1a1a5c61d454043c1d265"}, - {file = "PyYAML-5.1.1-cp27-cp27m-win_amd64.whl", hash = "sha256:a0f329125a926876f647c9fa0ef32801587a12328b4a3c741270464e3e4fa778"}, - {file = "PyYAML-5.1.1-cp34-cp34m-win32.whl", hash = "sha256:cd0618c5ba5bda5f4039b9398bb7fb6a317bb8298218c3de25c47c4740e4b95e"}, - {file = "PyYAML-5.1.1-cp34-cp34m-win_amd64.whl", hash = "sha256:57acc1d8533cbe51f6662a55434f0dbecfa2b9eaf115bede8f6fd00115a0c0d3"}, - {file = "PyYAML-5.1.1-cp35-cp35m-win32.whl", hash = "sha256:ceacb9e5f8474dcf45b940578591c7f3d960e82f926c707788a570b51ba59190"}, - {file = "PyYAML-5.1.1-cp35-cp35m-win_amd64.whl", hash = "sha256:fe6a88094b64132c4bb3b631412e90032e8cfe9745a58370462240b8cb7553cd"}, - {file = "PyYAML-5.1.1-cp36-cp36m-win32.whl", hash = "sha256:68c8dd247f29f9a0d09375c9c6b8fdc64b60810ebf07ba4cdd64ceee3a58c7b7"}, - {file = "PyYAML-5.1.1-cp36-cp36m-win_amd64.whl", hash = "sha256:588c94b3d16b76cfed8e0be54932e5729cc185caffaa5a451e7ad2f7ed8b4043"}, - {file = "PyYAML-5.1.1-cp37-cp37m-win32.whl", hash = "sha256:a3c252ab0fa1bb0d5a3f6449a4826732f3eb6c0270925548cac342bc9b22c225"}, - {file = "PyYAML-5.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:86a93cccd50f8c125286e637328ff4eef108400dd7089b46a7be3445eecfa391"}, - {file = "PyYAML-5.1.1.tar.gz", hash = "sha256:b4bb4d3f5e232425e25dda21c070ce05168a786ac9eda43768ab7f3ac2770955"}, -] -requests = [ - {file = "requests-2.22.0-py2.py3-none-any.whl", hash = "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"}, - {file = "requests-2.22.0.tar.gz", hash = "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4"}, -] -six = [ - {file = "six-1.12.0-py2.py3-none-any.whl", hash = "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c"}, - {file = "six-1.12.0.tar.gz", hash = "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"}, -] -snowballstemmer = [ - {file = "snowballstemmer-1.9.0.tar.gz", hash = "sha256:9f3b9ffe0809d174f7047e121431acf99c89a7040f0ca84f94ba53a498e6d0c9"}, -] -sphinx = [ - {file = "Sphinx-2.1.2-py3-none-any.whl", hash = "sha256:22538e1bbe62b407cf5a8aabe1bb15848aa66bb79559f42f5202bbce6b757a69"}, - {file = "Sphinx-2.1.2.tar.gz", hash = "sha256:f9a79e746b87921cabc3baa375199c6076d1270cee53915dbd24fdbeaaacc427"}, -] -sphinx-autobuild = [ - {file = "sphinx-autobuild-0.7.1.tar.gz", hash = "sha256:66388f81884666e3821edbe05dd53a0cfb68093873d17320d0610de8db28c74e"}, - {file = "sphinx_autobuild-0.7.1-py2-none-any.whl", hash = "sha256:e60aea0789cab02fa32ee63c7acae5ef41c06f1434d9fd0a74250a61f5994692"}, -] -sphinx-multiversion = [ - {file = "sphinx-multiversion-0.2.4.tar.gz", hash = "sha256:5cd1ca9ecb5eed63cb8d6ce5e9c438ca13af4fa98e7eb6f376be541dd4990bcb"}, - {file = "sphinx_multiversion-0.2.4-py3-none-any.whl", hash = "sha256:dec29f2a5890ad68157a790112edc0eb63140e70f9df0a363743c6258fbeb478"}, -] -sphinx-rtd-theme = [ - {file = "sphinx_rtd_theme-0.4.3-py2.py3-none-any.whl", hash = "sha256:00cf895504a7895ee433807c62094cf1e95f065843bf3acd17037c3e9a2becd4"}, - {file = "sphinx_rtd_theme-0.4.3.tar.gz", hash = "sha256:728607e34d60456d736cc7991fd236afb828b21b82f956c5ea75f94c8414040a"}, -] -sphinx-sitemap = [ - {file = "sphinx-sitemap-2.2.0.tar.gz", hash = "sha256:65adda39233cb17c0da10ba1cebaa2df73e271cdb6f8efd5cec8eef3b3cf7737"}, -] -sphinxcontrib-applehelp = [ - {file = "sphinxcontrib-applehelp-1.0.1.tar.gz", hash = "sha256:edaa0ab2b2bc74403149cb0209d6775c96de797dfd5b5e2a71981309efab3897"}, - {file = "sphinxcontrib_applehelp-1.0.1-py2.py3-none-any.whl", hash = "sha256:fb8dee85af95e5c30c91f10e7eb3c8967308518e0f7488a2828ef7bc191d0d5d"}, -] -sphinxcontrib-devhelp = [ - {file = "sphinxcontrib-devhelp-1.0.1.tar.gz", hash = "sha256:6c64b077937330a9128a4da74586e8c2130262f014689b4b89e2d08ee7294a34"}, - {file = "sphinxcontrib_devhelp-1.0.1-py2.py3-none-any.whl", hash = "sha256:9512ecb00a2b0821a146736b39f7aeb90759834b07e81e8cc23a9c70bacb9981"}, -] -sphinxcontrib-disqus = [ - {file = "sphinxcontrib-disqus-1.1.0.tar.gz", hash = "sha256:e5e78bafda84565bb80bbf6b88ff847ffcc35c30dfddbe96f70cf54c84badeda"}, -] -sphinxcontrib-htmlhelp = [ - {file = "sphinxcontrib-htmlhelp-1.0.2.tar.gz", hash = "sha256:4670f99f8951bd78cd4ad2ab962f798f5618b17675c35c5ac3b2132a14ea8422"}, - {file = "sphinxcontrib_htmlhelp-1.0.2-py2.py3-none-any.whl", hash = "sha256:d4fd39a65a625c9df86d7fa8a2d9f3cd8299a3a4b15db63b50aac9e161d8eff7"}, -] -sphinxcontrib-jsmath = [ - {file = "sphinxcontrib-jsmath-1.0.1.tar.gz", hash = "sha256:a9925e4a4587247ed2191a22df5f6970656cb8ca2bd6284309578f2153e0c4b8"}, - {file = "sphinxcontrib_jsmath-1.0.1-py2.py3-none-any.whl", hash = "sha256:2ec2eaebfb78f3f2078e73666b1415417a116cc848b72e5172e596c871103178"}, -] -sphinxcontrib-qthelp = [ - {file = "sphinxcontrib-qthelp-1.0.2.tar.gz", hash = "sha256:79465ce11ae5694ff165becda529a600c754f4bc459778778c7017374d4d406f"}, - {file = "sphinxcontrib_qthelp-1.0.2-py2.py3-none-any.whl", hash = "sha256:513049b93031beb1f57d4daea74068a4feb77aa5630f856fcff2e50de14e9a20"}, -] -sphinxcontrib-serializinghtml = [ - {file = "sphinxcontrib-serializinghtml-1.1.3.tar.gz", hash = "sha256:c0efb33f8052c04fd7a26c0a07f1678e8512e0faec19f4aa8f2473a8b81d5227"}, - {file = "sphinxcontrib_serializinghtml-1.1.3-py2.py3-none-any.whl", hash = "sha256:db6615af393650bf1151a6cd39120c29abaf93cc60db8c48eb2dddbfdc3a9768"}, -] -tornado = [ - {file = "tornado-6.0.3-cp35-cp35m-win32.whl", hash = "sha256:c9399267c926a4e7c418baa5cbe91c7d1cf362d505a1ef898fde44a07c9dd8a5"}, - {file = "tornado-6.0.3-cp35-cp35m-win_amd64.whl", hash = "sha256:398e0d35e086ba38a0427c3b37f4337327231942e731edaa6e9fd1865bbd6f60"}, - {file = "tornado-6.0.3-cp36-cp36m-win32.whl", hash = "sha256:4e73ef678b1a859f0cb29e1d895526a20ea64b5ffd510a2307b5998c7df24281"}, - {file = "tornado-6.0.3-cp36-cp36m-win_amd64.whl", hash = "sha256:349884248c36801afa19e342a77cc4458caca694b0eda633f5878e458a44cb2c"}, - {file = "tornado-6.0.3-cp37-cp37m-win32.whl", hash = "sha256:559bce3d31484b665259f50cd94c5c28b961b09315ccd838f284687245f416e5"}, - {file = "tornado-6.0.3-cp37-cp37m-win_amd64.whl", hash = "sha256:abbe53a39734ef4aba061fca54e30c6b4639d3e1f59653f0da37a0003de148c7"}, - {file = "tornado-6.0.3.tar.gz", hash = "sha256:c845db36ba616912074c5b1ee897f8e0124df269468f25e4fe21fe72f6edd7a9"}, -] -urllib3 = [ - {file = "urllib3-1.25.3-py2.py3-none-any.whl", hash = "sha256:b246607a25ac80bedac05c6f282e3cdaf3afb65420fd024ac94435cabe6e18d1"}, - {file = "urllib3-1.25.3.tar.gz", hash = "sha256:dbe59173209418ae49d485b87d1681aefa36252ee85884c31346debd19463232"}, -] -watchdog = [ - {file = "watchdog-0.9.0.tar.gz", hash = "sha256:965f658d0732de3188211932aeb0bb457587f04f63ab4c1e33eab878e9de961d"}, -] diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index b7be681..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,54 +0,0 @@ -[tool.poetry] -name = "magic-python" -version = "3.0.0" -description = "" -authors = ["iswbm "] - -[tool.poetry.dependencies] -python = "^3.8" -alabaster = "0.7.12" -argh = "0.26.2" -Babel = "2.7.0" -certifi = "2019.6.16" -chardet = "3.0.4" -docutils = "0.14" -idna = "2.8" -imagesize = "1.1.0" -Jinja2 = "2.10.1" -livereload = "2.6.1" -MarkupSafe = "1.1.1" -packaging = "19.0" -pathtools = "0.1.2" -port-for = "0.3.1" -Pygments = "2.4.2" -pyparsing = "2.4.0" -pytz = "2019.1" -PyYAML = "5.1.1" -requests = "2.22.0" -six = "1.12.0" -snowballstemmer = "1.9.0" -Sphinx = "2.1.2" -sphinx-autobuild = "0.7.1" -sphinx-rtd-theme = "0.4.3" -sphinxcontrib-applehelp = "1.0.1" -sphinxcontrib-devhelp = "1.0.1" -sphinxcontrib-htmlhelp = "1.0.2" -sphinxcontrib-jsmath = "1.0.1" -sphinxcontrib-qthelp = "1.0.2" -sphinxcontrib-serializinghtml = "1.1.3" -tornado = "6.0.3" -urllib3 = "1.25.3" -watchdog = "0.9.0" -sphinxcontrib-disqus = "1.1.0" -sphinx-sitemap = "2.2.0" -sphinx-multiversion = "0.2.4" - -[tool.poetry.dev-dependencies] - -[build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" - -[[tool.poetry.source]] -name = "aliyun" -url = "https://mirrors.aliyun.com/pypi/simple/" diff --git a/requirements.txt b/requirements.txt index 2d7be4e..b22584c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,21 +1,21 @@ alabaster==0.7.12 argh==0.26.2 -Babel==2.7.0 +Babel==2.9.1 certifi==2019年6月16日 chardet==3.0.4 docutils==0.14 idna==2.8 imagesize==1.1.0 -Jinja2==2.10.1 +Jinja2==2.11.3 livereload==2.6.1 MarkupSafe==1.1.1 packaging==19.0 pathtools==0.1.2 port-for==0.3.1 -Pygments==2.4.2 +Pygments==2.7.4 pyparsing==2.4.0 pytz==2019.1 -PyYAML==5.1.1 +PyYAML==5.4 requests==2.22.0 six==1.12.0 snowballstemmer==1.9.0 @@ -29,7 +29,7 @@ sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.2 sphinxcontrib-serializinghtml==1.1.3 tornado==6.0.3 -urllib3==1.25.3 +urllib3==1.26.5 watchdog==0.9.0 sphinxcontrib-disqus==1.1.0 sphinxcontrib-applehelp==1.0.1 From f26e8185d2817bffd3450938ebcdd94ee7fa904e Mon Sep 17 00:00:00 2001 From: iswbm Date: 2024年6月16日 23:22:22 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20baidutongji.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_static/js/baidutongji.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/_static/js/baidutongji.js b/source/_static/js/baidutongji.js index 0a7873f..dd5ee36 100644 --- a/source/_static/js/baidutongji.js +++ b/source/_static/js/baidutongji.js @@ -1,7 +1,7 @@ var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); - hm.src = "https://hm.baidu.com/hm.js?26ee367cf320d48d046542295cdb0dad"; + hm.src = "https://hm.baidu.com/hm.js?f15534298fc176a5524b6da87883f37f"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); From 36030c53cc65794ac79994713034099ed95211d0 Mon Sep 17 00:00:00 2001 From: iswbm Date: 2024年6月19日 21:48:35 +0800 Subject: [PATCH 11/14] update requirements.txt to python3.10.12 --- requirements.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index b22584c..08d22be 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ Babel==2.9.1 certifi==2019年6月16日 chardet==3.0.4 docutils==0.14 -idna==2.8 imagesize==1.1.0 Jinja2==2.11.3 livereload==2.6.1 @@ -15,8 +14,8 @@ port-for==0.3.1 Pygments==2.7.4 pyparsing==2.4.0 pytz==2019.1 -PyYAML==5.4 -requests==2.22.0 +PyYAML==6.0.1 +requests==2.32.3 six==1.12.0 snowballstemmer==1.9.0 Sphinx==2.1.2 @@ -29,7 +28,7 @@ sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.2 sphinxcontrib-serializinghtml==1.1.3 tornado==6.0.3 -urllib3==1.26.5 +urllib3==2.2.2 watchdog==0.9.0 sphinxcontrib-disqus==1.1.0 sphinxcontrib-applehelp==1.0.1 From 5b83fa7751161e642a727759d51ffb64d02e0c89 Mon Sep 17 00:00:00 2001 From: iswbm Date: 2024年6月19日 22:30:20 +0800 Subject: [PATCH 12/14] update requirements.txt to python3.10.12 --- rebuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebuild.sh b/rebuild.sh index 10883b9..7ff2b6c 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -1,4 +1,4 @@ -cat << EOF>/usr/local/lib/python3.6/site-packages/sphinx_rtd_theme/comments.html +cat << EOF>/usr/local/lib/python3.10/site-packages/sphinx_rtd_theme/comments.html src="https://utteranc.es/client.js" repo="iswbm/magic-python" From ba3139de80307dfc38178cfac2c2d69e00963f53 Mon Sep 17 00:00:00 2001 From: iswbm Date: 2026年1月26日 22:11:44 +0800 Subject: [PATCH 13/14] update requirements.txt to python3.6.8 --- rebuild.sh | 2 +- requirements.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rebuild.sh b/rebuild.sh index 7ff2b6c..10883b9 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -1,4 +1,4 @@ -cat << EOF>/usr/local/lib/python3.10/site-packages/sphinx_rtd_theme/comments.html +cat << EOF>/usr/local/lib/python3.6/site-packages/sphinx_rtd_theme/comments.html src="https://utteranc.es/client.js" repo="iswbm/magic-python" diff --git a/requirements.txt b/requirements.txt index 08d22be..2a34b8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,7 +15,7 @@ Pygments==2.7.4 pyparsing==2.4.0 pytz==2019.1 PyYAML==6.0.1 -requests==2.32.3 +#requests==2.32.3 six==1.12.0 snowballstemmer==1.9.0 Sphinx==2.1.2 @@ -28,7 +28,7 @@ sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.2 sphinxcontrib-serializinghtml==1.1.3 tornado==6.0.3 -urllib3==2.2.2 +#urllib3==2.2.2 watchdog==0.9.0 sphinxcontrib-disqus==1.1.0 sphinxcontrib-applehelp==1.0.1 From da288fdc4a697607f8ece9324b504fc4ffd4dfac Mon Sep 17 00:00:00 2001 From: iswbm Date: 2026年1月26日 22:11:54 +0800 Subject: [PATCH 14/14] remove readmore.js --- source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/conf.py b/source/conf.py index 62b302b..f3f5908 100644 --- a/source/conf.py +++ b/source/conf.py @@ -100,7 +100,7 @@ sys.path.append(os.path.abspath(_exts)) html_js_files = [ - 'js/readmore.js', +# 'js/readmore.js', 'js/baidutongji.js', ]

AltStyle によって変換されたページ (->オリジナル) /