协程简单程序(python3.5)
2016-07-29 15:05
218 查看
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()配合使用。
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()配合使用。
相关文章推荐
- window安装python3.5版本和简单的编译使用写一个简单的程序
- Python 3.5 编写简单的百度贴吧采集程序
- 用 python 做简单的网页爬虫程序
- Python源码分析2 - 一个简单的Python程序的执行
- Python写的一个简单的下载程序
- 用python写一个简单的去除源程序代码中行号的程序
- Python:简单的摄像头程序实现
- Python与C++ 程序的简单实例对比
- 简单调试 Python 程序
- Python简单的多客户端聊天室程序
- 简单的python程序--图形输出数字参数序列
- 转载:Python 与 C++ 程序的简单实例对比
- python简单的可逆加密程序
- Python与C++ 程序的简单实例对比
- python3.2 一个简单的socket 程序
- 用 python 做简单的网页爬虫程序
- Moblin的简单Python程序开发
- Python socket 简单示例程序
- 一个简单的根据行数对大文件进行分片的python程序
- python简单的tcp客户端发送程序