开发者

python system call

having a difficult time understanding how to get python to call a system function...

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

Trying to get pyt开发者_如何学Chon to build another file with my search string.

Thanks!


I recommend the PyMotW Subprocess page from Doug Hellmann who (quoted) "Reads the docs so you don't have to"

Apart from that:

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, 

if you need to match regular expressions apart from the documentation in the Python Standard Library documentation for the re module also refer to the PyMotW Regular Expression page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜