小编use*_*194的帖子

在python中,如何打印不包含某个字符串的行,而不是打印包含某个字符串的行:

我试图压缩一个非常大的日志文件,为此,我必须删除包含字符串"StatusRequest"和"StatusResponse"的每一行,同时打印其他行没有这个字符串.到目前为止我的代码如下(从命令提示符运行):

   if (sys.argv[1])=="--help":
       print ("\n")
       print ("Argument 1: Enter name of '.py' file")
       print ("-i or --input: name of Catalina log")
       print ("-o or --output: file to output to")
       print ("\n")
   if (sys.argv[1])=="-h":
       print ("\n")
       print ("Argument 1: Enter name of '.py' file")
       print ("-i or --input: name of Catalina log")
       print ("-o or --output: file to output to")
       print ("\n")

   else:
       print 'Number of arguments:', len(sys.argv), 'arguments.'
       print 'Argument List:', str(sys.argv)

       Numarg = (len(sys.argv))
       i=1
       while i<=(Numarg-4):
           search1="StatusRequest"
           search2="StatusResponse" …
Run Code Online (Sandbox Code Playgroud)

python printing if-statement contains python-2.7

9
推荐指数
2
解决办法
4万
查看次数

标签 统计

contains ×1

if-statement ×1

printing ×1

python ×1

python-2.7 ×1