发布网友 发布时间:2022-04-22 03:11
共1个回答
热心网友 时间:2022-05-10 05:39
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()