首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python系统调用

python系统调用
EN

Stack Overflow用户
提问于 2011-06-22 05:14:16
回答 1查看 2K关注 0票数 0

很难理解如何让python调用系统函数……

代码语言:javascript
复制
the_file = ('logs/consolidated.log.gz')         
webstuff = subprocess.Popen(['/usr/bin/zgrep', '/meatsauce/', the_file ],stdout=subprocess.PIPE) % dpt_search
    for line in webstuff.stdout:
        print line

正在尝试让python使用我的搜索字符串构建另一个文件。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-22 06:00:17

我推荐Doug Hellmann的PyMotW Subprocess page,他(引用)“阅读文档,这样你就不需要”。

除此之外:

代码语言:javascript
复制
f = file('sourcefile')
for line in f:
    if 'pattern' in line:
            # mind the , at the end,
            # since there's no stripping involved
            # and print adds a newline without it
            print line, 

如果除了Python Standard Library documentation for the re module中的文档外,还需要匹配正则表达式,请参阅PyMotW Regular Expression page

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6436740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档