文本文件包含
paragraph 1:
01 internet 1
02 intranet 2
paragraph 2:
03 internet 1
04 intranet 2
paragraph 3:
05 internet 1
06 intranet 2
paragraph 4:
07 internet 1
08 intranet 2
我想使用 python 在第 2 段中找到 Intranet 2。
这是我到目前为止所拥有的:
file = open( "c:\file.txt", "r" ).readlines()
var = raw_input("enter the value")
var1 = "paragraph 1:"
for line in file:
if re.search(var1, line,re.IGNORECASE):
print re.search(var, line,re.IGNORECASE)
print "found", line
count=line for line in file:
if re.search(var, line,re.IGNORECASE):
print "value=", line