python 流式编程_python 使用yield进行数据的流式处理
demo:從文件中取包含字符“a”的5行數據做一次批處理!!!
# coding: utf-8
import time
def cat(f):
for line in f:
yield line
def grep(lines,searchtext):
for line in lines:
if searchtext in line:
yield line
def process(segment_lines):
print (segment_lines)
flog = cat(open(‘/tmp/tflearn_logs/vae/events.out.tfevents.1540467860.lanzihuazaideMacBook-Pro.local‘))
pylines = grep(flog, ‘a‘)
segment_lines = []
for line in pylines:
if len(segment_lines) < 5:
segment_lines.append(line)
else:
print ("*"*88)
process(segment_lines)
segment_lines = []
if segment_lines:
print ("*"*88)
process(segment_lines)
原文地址:https://www.cnblogs.com/bonelee/p/9855445.html
總結
以上是生活随笔為你收集整理的python 流式编程_python 使用yield进行数据的流式处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python能做高频交易吗_python
- 下一篇: com 组件调用不起来_一文读懂Eure