GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — article/python/python_file_yield.md at master · pythonpeixun/article

Expand file tree

/

python_file_yield.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
42 lines (27 loc) · 1.17 KB
/

python_file_yield.md

Copy path

File metadata and controls

42 lines (27 loc) · 1.17 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

#python生成器处理文本文件大幅度提高效率

如果你感觉黄哥的文章对你有帮助请打赏,支付宝账号:[email protected]

运维需要处理日志文件,感觉对自己写的代码处理速度不是很满意。

黄哥建议试试生成器,可以大幅度提高效率。

请看代码

#coding:utf-8
"""
python远程视频培训
https://github.com/pythonpeixun/article/blob/master/index.md
c语言从入门到精通远程视频培训
https://github.com/pythonpeixun/article/blob/master/c_course.md
咨询:qq:1465376564  黄哥python培训
"""
import time

start_time = time.time()


def find_ip(path):
    for line in open(path):
        s = line.find('"Sogou web spider')
        if s >= 0:
            yield line[:s].strip()

p = find_ip("bigfile.txt")
p = list(set(list(p)))

for item in p:
    print item

print time.time() - start_time, "seconds"

点击黄哥python培训试看视频播放地址

黄哥python远程视频培训班

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.