pycharm中编写的plx12:
def print_matches(matchtxt):
print("looking for ",matchtxt)
while True:
line=(yield)
if matchtxt in line :
print(line)
命令窗口运行:
>>> import sys
>>> sys.path.append("D:\plx")
>>> import plx12
>>> matcher=plx12.print_matches("python")
>>> matcher.__next__()
lookingfor python
>>> matcher.send("hello word")
>>> matcher.send("python is cool")
pythonis cool
>>> matcher.send("yow")
>>>matcher.close()
该程序实现的是简单的匹配。
利用(yield)与send()配合使用。