-1

我有一个 python 程序,它将 cat 一个文件,然后仅当在输出中找到单词“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
4

1 回答 1

1

怎么样:

if not "oranges" in out:
    print out
于 2016-11-28T19:51:26.070 回答