import re
sum=0
file = open("pro.txt").readlines()
for lines in file:
word= len(re.findall('(^|[^\w\-])able#1(?=([^\w\-]|$))', lines))
if word>0:
sum=sum+1
pro.txt如何使用python从文本文件中检索值?
0 6 9 able#1
0 11 34 unable#1
9 12 22 able#1
0 6 9 able#1-able#1
0 11 34 unable#1*able#1
我想这个词的价值,就像如果用户输入的句子,它包含单词能比它取回针对它的价值就像9 6 0
或0 6 9
,但现在作为一个样本,我只是想,如果我在这个txt文件只专注于能#1字我怎样才能通过它检索值,因为我只是想它在某种程度上分裂,并不仅仅是把队列上
for lines in file:
k=lines.split()
print k
['0', '6', '9', 'able#1', 'you#1']
['0', '11', '34', 'unable#1']
['9', '12', '22', 'able#1']
['0', '6', '9', 'able#1-able#1']
['0', '11', '34', 'unable#1*able#1']
['9', '12', '22', 'able#1_able#1']
预计产量:
enter the word you want to find in text file : able#1
word found !!
values are
0 6 9
什么是您预期的输出? – ATOzTOA 2013-02-26 18:06:25