# -*- coding:utf-8 -*-
__author__ = 'Jipu FANG'
import requests
f = open('123.txt', 'r+')
a=f.readlines()
b = '115'
if [c.strip().find(b) for c in a ]:
print("%s 已经存在!" %(b))
else:
f.write(b)
f.close()
# 自己去完善吧!也是一种学习!
# -*- coding:utf-8 -*-
__author__ = 'niubiqigai'
executeRecord="niu"
rec = open('py.txt', 'r+')
lineInfos = rec.readlines()
recordFlag = True
for row in lineInfos:
print(row.strip().find(executeRecord))
# find函数-1表示找不到匹配内容,其他输出结果为找到的索引值
if row.strip().find(executeRecord) != -1:
print("%s 已经存在!" % (executeRecord))
# 记录过即不再记录
recordFlag = False
break
if recordFlag:
executeRecord = '%s\n' % executeRecord
rec.write(executeRecord)
rec.close()