摘要: 有一个event使用的例子,员工进公司门要刷卡, 我们这里设置一个线程是“门”, 再设置几个线程为“员工”,员工看到门没打开,就刷卡,刷完卡,门开了,员工就可以通过。 1 #_*_coding:utf-8_*_ 2 __author__ = 'Alex Li' 3 import threading 阅读全文
posted @ 2018-10-18 15:51 子觉 阅读(1379) 评论(0) 推荐(0) 编辑
摘要: 通过Event来实现两个或多个线程间的交互,下面是一个红绿灯的例子,即起动一个线程做交通指挥灯,生成几个线程做车辆,车辆行驶按红灯停,绿灯行的规则。 1 import threading,time 2 import random 3 def light(): 4 if not event.isSet 阅读全文
posted @ 2018-10-18 15:36 子觉 阅读(2590) 评论(0) 推荐(0) 编辑
摘要: 需求描述: 1、实现加减乘除及拓号优先级解析 2、用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )等类似公式后,必须自己解析里面的(),+,-,*,/符号和公 阅读全文
posted @ 2018-10-18 12:43 子觉 阅读(1827) 评论(0) 推荐(0) 编辑
摘要: '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r"^a","\nabc\neee",flags=re.MULTILINE) '$' 匹配字符结尾,或e.search("f 阅读全文
posted @ 2018-10-18 12:39 子觉 阅读(703) 评论(0) 推荐(0) 编辑
摘要: 匹配手机号: 1 phone_str = "hey my name is alex, and my phone number is 13651054607, please call me if you are pretty!" 2 phone_str2 = "hey my name is alex, 阅读全文
posted @ 2018-10-18 10:35 子觉 阅读(414) 评论(0) 推荐(0) 编辑