很难理解如何让python调用系统函数……
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使用我的搜索字符串构建另一个文件。
谢谢!
发布于 2011-06-22 06:00:17
我推荐Doug Hellmann的PyMotW Subprocess page,他(引用)“阅读文档,这样你就不需要”。
除此之外:
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
https://stackoverflow.com/questions/6436740
复制相似问题