我有一个python程序会捕获一个文件,然后只有在输出中找到“oranges”这个单词时才输出输出。我想知道如果在输出中找到“oranges”,我怎么能扭转这个并让程序不输出任何内容?
#! /usr/bin/python
import commands, os, string
import sys
import fileinput
import subprocess
from subprocess import Popen, PIPE
import shlex
cmd = "cat /root/newfile.txt"
args = shlex.split(cmd)
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if out.find("oranges") > -1:
print out
答案 0 :(得分:1)
怎么样:
if not "oranges" in out:
print out