Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
iswbm committed Feb 7, 2022
1 parent 46dca27 commit 9159476
Show file tree
Hide file tree
Showing 128 changed files with 392 additions and 1,001 deletions.
22 changes: 4 additions & 18 deletions md2rst.py
Original file line number Diff line number Diff line change
@@ -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 = '''
Expand Down
8 changes: 2 additions & 6 deletions source/c01/c01_01.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.1 默默无闻的省略号很好用
==========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

在Python中,一切皆对象,省略号也不例外。

Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_02.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.2 使用 end 来结束代码块
=========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

有不少编程语言,循环、判断代码块需要用 end
标明结束,这样一定程度上会使代码逻辑更加清晰一点。
Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_03.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.3 可直接运行的 zip 包
=======================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

我们可以经常看到有 Python 包,居然可以以 zip
包进行发布,并且可以不用解压直接使用。
Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_04.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.4 反斜杠的倔强: 不写最后
==========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

``\`` 在 Python 中的用法主要有两种

Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_05.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.5 如何修改解释器提示符
========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

这个当做今天的一个小彩蛋吧。应该算是比较冷门的,估计知道的人很少了吧。

Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_06.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.6 简洁而优雅的链式比较
========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

先给你看一个示例:

Expand All @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_07.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.7 and 和 or 的短路效应
========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

and 和 or 是我们再熟悉不过的两个逻辑运算符,在 Python 也有它的妙用。

Expand All @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_08.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.8 连接多个列表最极客的方式
============================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

.. code:: python
Expand All @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_09.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.9 字典居然是可以排序的?
==========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

在 Python 3.6 之前字典不可排序的思想,似乎已经根深蒂固。

Expand All @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_10.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.10 哪些情况下不需要续行符?
=============================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

在写代码时,为了代码的可读性,代码的排版是尤为重要的。

Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_11.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.11 用户无感知的小整数池
=========================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

为避免整数频繁申请和销毁内存空间,Python 定义了一个小整数池 [-5, 256]
这些整数对象是提前建立好的,不会被垃圾回收。
Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_12.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.12 神奇的 intern 机制
=======================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

字符串类型作为Python中最常用的数据类型之一,Python解释器为了提高字符串使用的效率和使用性能,做了很多优化。

Expand Down Expand Up @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_13.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.13 site-packages和 dist-packages
==================================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

如果你足够细心,你会在你的机器上,有些包是安装在 **site-packages**
下,而有些包安装在 **dist-packages** 下。
Expand All @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_14.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.14 argument 和 parameter 的区别?
==================================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

arguments 和 parameter
的翻译都是参数,在中文场景下,二者混用基本没有问题,毕竟都叫参数嘛。
Expand All @@ -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
23 changes: 7 additions & 16 deletions source/c01/c01_15.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.15 /usr/bin/env python 有什么用?
===================================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

我们经常会在别人的脚本或者项目的入口文件里看到第一行是下面这样

Expand All @@ -20,7 +20,7 @@
稍微接触过 linux 的人都知道 ``/usr/bin/python`` 就是我们执行 ``python``
进入console 模式里的 ``python``

|image1|
.. image:: http://image.iswbm.com/20200331184021.png

而当你在可执行文件头里使用 ``#!`` + ``/usr/bin/python``
,意思就是说你得用哪个软件 (python)来执行这个文件。
Expand All @@ -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 好像没什么区别呀

Expand All @@ -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
8 changes: 2 additions & 6 deletions source/c01/c01_16.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1.16 dict() 与 {} 生成空字典有什么区别?
========================================

|image0|
.. image:: http://image.iswbm.com/20200804124133.png

在初始化一个空字典时,有的人会写 dict(),而有的人会写成 {}

Expand Down Expand Up @@ -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
Loading

0 comments on commit 9159476

Please sign in to comment.