.find() function is used for find a substring in a string, and will return location index. E.g. -1 means no such substirng in this string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import io
import re
import sys
import codecs

keyword = u'车'
def getKeyWeibo(filename):

try:
with codecs.open(filename,'r',encoding='utf8') as cfg:
cfglist = cfg.readlines()
for i in range(len(cfglist)):
if cfglist[i].find(keyword) > 0:
f.write(cfglist[i]+'\n')

except Exception, e:
print e
print 'Please check checkboard.cfg,looks like something configured wrong.'