我有一个.txt文件(例如test.txt)。使用python,我想在这个.txt文件中搜索字符串“100%”。请帮忙。Python:我如何在.txt文件中查找'100%'作为字符串
file = open('test.txt', 'r')
for line in file.readlines():
if '100%' in line:
print "Successfully downloaded."
test.txt的一部分看起来像:
6800K .......... .......... ......... .......... .......... 98%11.1M 0s 6850K .......... .......... .. ........ .......... .......... 99%10.4M 0s 6900K .......... ..... ..... .......... ..........。 100%12.6M = 2.3s
我想在这个文件中寻找'100%'。
到目前为止你做了什么? – Jack 2012-03-09 23:48:52
file = open('test.txt','r') 对于file.readlines中的行(): 如果行中包含'100 \%': print“Successfull”。 – nsh 2012-03-09 23:51:42
你有什么好,除了你需要缩进打印和放下反斜杠。 – 2012-03-09 23:55:38