GeezerVison is showing github.com — 代码块内的「水哥」回滚为「两点水」,保留正文称谓 · WangLeGeWang/Python@0b26c68
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Article/PythonBasis/python10/2.md +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,7 @@ class User(object): | 13 | 13 | self.name = name; | 14 | 14 | self.age = age; | 15 | 15 |
| 16 | | -user=User('水哥',23) | | 16 | +user=User('两点水',23) | 17 | 17 | ``` | 18 | 18 |
| 19 | 19 | 实际上,创建一个类的过程是分为两步的,一步是创建类的对象,还有一步就是对类进行初始化。 | @@ -45,14 +45,14 @@ class User(object): | 45 | 45 |
| 46 | 46 |
| 47 | 47 | if __name__ == '__main__': | 48 | | - usr = User('水哥', 23) | | 48 | + usr = User('两点水', 23) | 49 | 49 | ``` | 50 | 50 |
| 51 | 51 | 看看输出的结果: | 52 | 52 |
| 53 | 53 | ```txt | 54 | 54 | 调用了 def __new__ 方法 | 55 | | -('水哥', 23) | | 55 | +('两点水', 23) | 56 | 56 | 调用了 def __init__ 方法 | 57 | 57 | ``` | 58 | 58 |
| |
Collapse file Copy file name to clipboardExpand all lines: Article/PythonBasis/python10/4.md +3-3Lines changed: 3 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | # -*- coding: UTF-8 -*- | 24 | 24 |
| 25 | 25 | class User(object): | 26 | | - def __init__(self, name='水哥', sex='男'): | | 26 | + def __init__(self, name='两点水', sex='男'): | 27 | 27 | self.sex = sex | 28 | 28 | self.name = name | 29 | 29 |
| @@ -37,7 +37,7 @@ class User(object): | 37 | 37 |
| 38 | 38 |
| 39 | 39 | class MyClass(object): | 40 | | - x = User('水哥', '男') | | 40 | + x = User('两点水', '男') | 41 | 41 | y = 5 | 42 | 42 |
| 43 | 43 |
| @@ -64,7 +64,7 @@ if __name__ == '__main__': | 64 | 64 |
| 65 | 65 | ```txt | 66 | 66 | 获取 name 值 | 67 | | -水哥 | | 67 | +两点水 | 68 | 68 |
| 69 | 69 |
| 70 | 70 | 设置 name 值 | |
Collapse file Copy file name to clipboardExpand all lines: Article/PythonBasis/python12/3.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -35,7 +35,7 @@ Python 中所有的东西,注意喔,这里是说所有的东西,他们都 | 35 | 35 | age = 23 | 36 | 36 | print(age.__class__) | 37 | 37 | # 字符串 | 38 | | -name = '水哥' | | 38 | +name = '两点水' | 39 | 39 | print(name.__class__) | 40 | 40 |
| 41 | 41 |
| |
Collapse file Copy file name to clipboardExpand all lines: Article/PythonBasis/python13/2.md +8-8Lines changed: 8 additions & 8 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -246,7 +246,7 @@ class Producer(threading.Thread): | 246 | 246 |
| 247 | 247 |
| 248 | 248 | cond = threading.Condition() | 249 | | -consumer = Consumer(cond, '买家(水哥)') | | 249 | +consumer = Consumer(cond, '买家(两点水)') | 250 | 250 | producer = Producer(cond, '卖家(三点水)') | 251 | 251 | consumer.start() | 252 | 252 | producer.start() | @@ -256,12 +256,12 @@ producer.start() | 256 | 256 | 输出的结果如下: | 257 | 257 |
| 258 | 258 | ```txt | 259 | | -买家(水哥): 我这两件商品一起买,可以便宜点吗 | | 259 | +买家(两点水): 我这两件商品一起买,可以便宜点吗 | 260 | 260 | 卖家(三点水): 可以的,你提交订单吧 | 261 | | -买家(水哥): 我已经提交订单了,你修改下价格 | | 261 | +买家(两点水): 我已经提交订单了,你修改下价格 | 262 | 262 | 卖家(三点水): 好了,已经修改了 | 263 | | -买家(水哥): 收到,我支付成功了 | 264 | | -买家(水哥): 等待收货 | | 263 | +买家(两点水): 收到,我支付成功了 | | 264 | +买家(两点水): 等待收货 | 265 | 265 | 卖家(三点水): 嗯,收款成功,马上给你发货 | 266 | 266 | 卖家(三点水): 发货商品 | 267 | 267 | ``` | @@ -282,7 +282,7 @@ isRead = True | 282 | 282 |
| 283 | 283 | def write(q): | 284 | 284 | # 写数据进程 | 285 | | - for value in ['水哥', '三点水', '四点水']: | | 285 | + for value in ['两点水', '三点水', '四点水']: | 286 | 286 | print(f'写进 Queue 的值为:{value}') | 287 | 287 | q.put(value) | 288 | 288 |
| @@ -305,9 +305,9 @@ if __name__ == '__main__': | 305 | 305 | 输出的结果如下: | 306 | 306 |
| 307 | 307 | ```txt | 308 | | -写进 Queue 的值为:水哥 | | 308 | +写进 Queue 的值为:两点水 | 309 | 309 | 写进 Queue 的值为:三点水 | 310 | | -从 Queue 读取的值为:水哥 | | 310 | +从 Queue 读取的值为:两点水 | 311 | 311 | 写进 Queue 的值为:四点水 | 312 | 312 | 从 Queue 读取的值为:三点水 | 313 | 313 | 从 Queue 读取的值为:四点水 | |
Collapse file Copy file name to clipboardExpand all lines: Article/PythonBasis/python13/3.md +12-12Lines changed: 12 additions & 12 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -34,9 +34,9 @@ def worker(interval, name): | 34 | 34 |
| 35 | 35 |
| 36 | 36 | if __name__ == "__main__": | 37 | | - p1 = multiprocessing.Process(target=worker, args=(2, '水哥1')) | 38 | | - p2 = multiprocessing.Process(target=worker, args=(3, '水哥2')) | 39 | | - p3 = multiprocessing.Process(target=worker, args=(4, '水哥3')) | | 37 | + p1 = multiprocessing.Process(target=worker, args=(2, '两点水1')) | | 38 | + p2 = multiprocessing.Process(target=worker, args=(3, '两点水2')) | | 39 | + p3 = multiprocessing.Process(target=worker, args=(4, '两点水3')) | 40 | 40 |
| 41 | 41 | p1.start() | 42 | 42 | p2.start() | @@ -57,12 +57,12 @@ child p.name:Process-3 p.id7600 | 57 | 57 | child p.name:Process-2 p.id5560 | 58 | 58 | child p.name:Process-1 p.id7716 | 59 | 59 | END!!!!!!!!!!!!!!!!! | 60 | | -水哥 1【start】 | 61 | | -水哥 2【start】 | 62 | | -水哥 3【start】 | 63 | | -水哥 1【end】 | 64 | | -水哥 2【end】 | 65 | | -水哥 3【end】 | | 60 | +两点水 1【start】 | | 61 | +两点水 2【start】 | | 62 | +两点水 3【start】 | | 63 | +两点水 1【end】 | | 64 | +两点水 2【end】 | | 65 | +两点水 3【end】 | 66 | 66 |
| 67 | 67 | Process finished with exit code 0 | 68 | 68 | ``` | @@ -293,7 +293,7 @@ import os, time, random | 293 | 293 | def write(q): | 294 | 294 | # 写数据进程 | 295 | 295 | print(f'写进程的PID:{os.getpid()}') | 296 | | - for value in ['水哥', '三点水', '四点水']: | | 296 | + for value in ['两点水', '三点水', '四点水']: | 297 | 297 | print(f'写进 Queue 的值为:{value}') | 298 | 298 | q.put(value) | 299 | 299 | time.sleep(random.random()) | @@ -328,8 +328,8 @@ if __name__ == '__main__': | 328 | 328 | ```txt | 329 | 329 | 读进程的PID:13208 | 330 | 330 | 写进程的PID:10864 | 331 | | -写进 Queue 的值为:水哥 | 332 | | -从 Queue 读取的值为:水哥 | | 331 | +写进 Queue 的值为:两点水 | | 332 | +从 Queue 读取的值为:两点水 | 333 | 333 | 写进 Queue 的值为:三点水 | 334 | 334 | 从 Queue 读取的值为:三点水 | 335 | 335 | 写进 Queue 的值为:四点水 | |
Collapse file Copy file name to clipboardExpand all lines: Article/PythonBasis/python14/1.md +13-13Lines changed: 13 additions & 13 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,19 +10,19 @@ Python 自 1.5 版本起增加了re 模块,它提供 Perl 风格的正则表 | 10 | 10 |
| 11 | 11 | ```python | 12 | 12 | # 设定一个常量 | 13 | | -a = '水哥|twowater|liangdianshui|草根程序员|ReadingWithU' | | 13 | +a = '两点水|twowater|liangdianshui|草根程序员|ReadingWithU' | 14 | 14 |
| 15 | | -# 判断是否有 “水哥” 这个字符串,使用 PY 自带函数 | | 15 | +# 判断是否有 “两点水” 这个字符串,使用 PY 自带函数 | 16 | 16 |
| 17 | | -print(f'是否含有“水哥”这个字符串:{a.index("水哥") > -1}') | 18 | | -print(f'是否含有“水哥”这个字符串:{"水哥" in a}') | | 17 | +print(f'是否含有“两点水”这个字符串:{a.index("两点水") > -1}') | | 18 | +print(f'是否含有“两点水”这个字符串:{"两点水" in a}') | 19 | 19 | ``` | 20 | 20 |
| 21 | 21 | 输出的结果如下: | 22 | 22 |
| 23 | 23 | ```txt | 24 | | -是否含有“水哥”这个字符串:True | 25 | | -是否含有“水哥”这个字符串:True | | 24 | +是否含有“两点水”这个字符串:True | | 25 | +是否含有“两点水”这个字符串:True | 26 | 26 | ``` | 27 | 27 |
| 28 | 28 | 那么,如果使用正则表达式呢? | @@ -40,25 +40,25 @@ re.findall(pattern, string[, flags]) | 40 | 40 | import re | 41 | 41 |
| 42 | 42 | # 设定一个常量 | 43 | | -a = '水哥|twowater|liangdianshui|草根程序员|ReadingWithU' | | 43 | +a = '两点水|twowater|liangdianshui|草根程序员|ReadingWithU' | 44 | 44 |
| 45 | 45 | # 正则表达式 | 46 | 46 |
| 47 | | -findall = re.findall('水哥', a) | | 47 | +findall = re.findall('两点水', a) | 48 | 48 | print(findall) | 49 | 49 |
| 50 | 50 | if len(findall) > 0: | 51 | | - print('a 含有“水哥”这个字符串') | | 51 | + print('a 含有“两点水”这个字符串') | 52 | 52 | else: | 53 | | - print('a 不含有“水哥”这个字符串') | | 53 | + print('a 不含有“两点水”这个字符串') | 54 | 54 |
| 55 | 55 | ``` | 56 | 56 |
| 57 | 57 | 输出的结果: | 58 | 58 |
| 59 | 59 | ```txt | 60 | | -['水哥'] | 61 | | -a 含有“水哥”这个字符串 | | 60 | +['两点水'] | | 61 | +a 含有“两点水”这个字符串 | 62 | 62 | ``` | 63 | 63 |
| 64 | 64 | 从输出结果可以看到,可以实现和内置函数一样的功能,可是在这里也要强调一点,上面这个例子只是方便我们理解正则表达式,这个正则表达式的写法是毫无意义的。为什么这样说呢? | @@ -72,7 +72,7 @@ a 含有“水哥”这个字符串 | 72 | 72 | import re | 73 | 73 |
| 74 | 74 | # 设定一个常量 | 75 | | -a = '水哥|twowater|liangdianshui|草根程序员|ReadingWithU' | | 75 | +a = '两点水|twowater|liangdianshui|草根程序员|ReadingWithU' | 76 | 76 |
| 77 | 77 | # 选择 a 里面的所有小写英文字母 | 78 | 78 |
| |
Collapse file Copy file name to clipboardExpand all lines: Article/PythonBasis/python16/1.md +16-16Lines changed: 16 additions & 16 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 |
| 6 | 6 | ```Python | 7 | 7 | def punch(): | 8 | | - print('昵称:水哥 部门:做鸭事业部 上班打卡成功') | | 8 | + print('昵称:两点水 部门:做鸭事业部 上班打卡成功') | 9 | 9 |
| 10 | 10 |
| 11 | 11 | punch() | @@ -14,7 +14,7 @@ punch() | 14 | 14 | 输出的结果如下: | 15 | 15 |
| 16 | 16 | ``` | 17 | | -昵称:水哥 部门:做鸭事业部 上班打卡成功 | | 17 | +昵称:两点水 部门:做鸭事业部 上班打卡成功 | 18 | 18 | ``` | 19 | 19 |
| 20 | 20 | 然后,产品反馈,不行啊,怎么上班打卡没有具体的日期,加上打卡的具体日期吧,这应该很简单,分分钟解决啦。好吧,那就直接添加打印日期的代码吧,如下: | @@ -25,7 +25,7 @@ import time | 25 | 25 |
| 26 | 26 | def punch(): | 27 | 27 | print(time.strftime('%Y-%m-%d', time.localtime(time.time()))) | 28 | | - print('昵称:水哥 部门:做鸭事业部 上班打卡成功') | | 28 | + print('昵称:两点水 部门:做鸭事业部 上班打卡成功') | 29 | 29 |
| 30 | 30 |
| 31 | 31 | punch() | @@ -35,7 +35,7 @@ punch() | 35 | 35 |
| 36 | 36 | ``` | 37 | 37 | 2018-01-09 | 38 | | -昵称:水哥 部门:做鸭事业部 上班打卡成功 | | 38 | +昵称:两点水 部门:做鸭事业部 上班打卡成功 | 39 | 39 | ``` | 40 | 40 |
| 41 | 41 | 这样改是可以,可是这样改是改变了函数的功能结构的,本身这个函数定义的时候就是打印某个员工的信息和提示打卡成功,现在增加打印日期的代码,可能会造成很多代码重复的问题。比如,还有一个地方只需要打印员工信息和打卡成功就行了,不需要日期,那么你又要重写一个函数吗?而且打印当前日期的这个功能方法是经常使用的,是可以作为公共函数给各个模块方法调用的。当然,这都是作为一个整体项目来考虑的。 | @@ -47,7 +47,7 @@ import time | 47 | 47 |
| 48 | 48 |
| 49 | 49 | def punch(): | 50 | | - print('昵称:水哥 部门:做鸭事业部 上班打卡成功') | | 50 | + print('昵称:两点水 部门:做鸭事业部 上班打卡成功') | 51 | 51 |
| 52 | 52 |
| 53 | 53 | def add_time(func): | @@ -62,7 +62,7 @@ add_time(punch) | 62 | 62 |
| 63 | 63 | ``` | 64 | 64 | 2018-01-09 | 65 | | -昵称:水哥 部门:做鸭事业部 上班打卡成功 | | 65 | +昵称:两点水 部门:做鸭事业部 上班打卡成功 | 66 | 66 | ``` | 67 | 67 |
| 68 | 68 |
| @@ -73,7 +73,7 @@ import time | 73 | 73 |
| 74 | 74 |
| 75 | 75 | def punch(): | 76 | | - print('昵称:水哥 部门:做鸭事业部 上班打卡成功') | | 76 | + print('昵称:两点水 部门:做鸭事业部 上班打卡成功') | 77 | 77 |
| 78 | 78 |
| 79 | 79 | def add_time(func): | @@ -94,7 +94,7 @@ add_time(holiday) | 94 | 94 |
| 95 | 95 | ``` | 96 | 96 | 2018-01-09 | 97 | | -昵称:水哥 部门:做鸭事业部 上班打卡成功 | | 97 | +昵称:两点水 部门:做鸭事业部 上班打卡成功 | 98 | 98 | 2018-01-09 | 99 | 99 | 天气太冷,今天放假 | 100 | 100 | ``` | @@ -114,7 +114,7 @@ def decorator(func): | 114 | 114 |
| 115 | 115 |
| 116 | 116 | def punch(): | 117 | | - print('昵称:水哥 部门:做鸭事业部 上班打卡成功') | | 117 | + print('昵称:两点水 部门:做鸭事业部 上班打卡成功') | 118 | 118 |
| 119 | 119 |
| 120 | 120 | f = decorator(punch) | | 125 | 125 |
| 126 | 126 | ``` | 127 | 127 | 2018-01-09 | 128 | | -昵称:水哥 部门:做鸭事业部 上班打卡成功 | | 128 | +昵称:两点水 部门:做鸭事业部 上班打卡成功 | 129 | 129 | ``` | 130 | 130 |
| 131 | 131 | 通过代码,能知道装饰器函数一般做这三件事: | @@ -154,7 +154,7 @@ def decorator(func): | 154 | 154 |
| 155 | 155 | @decorator | 156 | 156 | def punch(): | 157 | | - print('昵称:水哥 部门:做鸭事业部 上班打卡成功') | | 157 | + print('昵称:两点水 部门:做鸭事业部 上班打卡成功') | 158 | 158 |
| 159 | 159 | punch() | 160 | 160 | ``` | @@ -163,7 +163,7 @@ punch() | 163 | 163 |
| 164 | 164 | ``` | 165 | 165 | 2018-01-09 | 166 | | -昵称:水哥 部门:做鸭事业部 上班打卡成功 | | 166 | +昵称:两点水 部门:做鸭事业部 上班打卡成功 | 167 | 167 | ``` | 168 | 168 |
| 169 | 169 | 那么这就很方便了,方便在我们的调用上,比如例子中的,使用了装饰器后,直接在原本的函数上加上装饰器的语法糖就可以了,本函数也无虚任何改变,调用的地方也不需修改。 | @@ -195,17 +195,17 @@ def print_args(reason, **kwargs): | 195 | 195 | print(kwargs) | 196 | 196 |
| 197 | 197 |
| 198 | | -punch('水哥', '做鸭事业部') | 199 | | -print_args('水哥', sex='男', age=99) | | 198 | +punch('两点水', '做鸭事业部') | | 199 | +print_args('两点水', sex='男', age=99) | 200 | 200 | ``` | 201 | 201 |
| 202 | 202 | 输出结果如下: | 203 | 203 |
| 204 | 204 | ``` | 205 | 205 | 2018-01-09 | 206 | | -昵称:水哥 部门:做鸭事业部 上班打卡成功 | | 206 | +昵称:两点水 部门:做鸭事业部 上班打卡成功 | 207 | 207 | 2018-01-09 | 208 | | -水哥 | | 208 | +两点水 | 209 | 209 | {'sex': '男', 'age': 99} | 210 | 210 | ``` | 211 | 211 |
| |
|