尽管Python存在,但它不会找到字符串

时间:2014-02-06 16:54:18

标签: python

我有一个相对简单的脚本试图解析文本文件。我正在寻找带有文字的行

  

[新代理/ UDP]

在文本文件中,因此我使用:

for line in file_lines:
    if "[new Agent/UDP]" in line:
        print "found"

问题是即使它存在,它也永远不会找到该行。在同一行,“set”这个词存在并找到它,但我需要在我之前提到的字符串之后识别一行。

更新:

好的,所以复制粘贴的代码是:

    for line in file_ns_lines:
        if source_name in line:
            if "[new Agent/UDP]" in line:
                print "found"

以下是文件中的几行

set tg0sink0 [new Agent/Null]
set tg0src0 [new Agent/UDP]
set tg1sink0 [new Agent/TCPSink]
set tg1src0 [new Agent/TCP]
在这种情况下,

source_name将是tg0src0

0 个答案:

没有答案