我有一个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
怎么样:
if not "oranges" in out:
print out