# This is a sample Python script.
import os
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def markjobdone() :
path = os.getcwd() #获取当前路径
# path = os.path.abspath('.')#获取绝对路径2
jobdone = '--finished'
with open((r'%s\\111.txt' % path), 'r+', encoding='utf-8') as rf:#打开当前路径下的111.txt文件,第一个\是转义,第二个\表示本地的路径
contents = rf.read()#读取txt文件内容转化为列表
# print(contents)
newstring =''.join(contents)#列表转字符串
flag = None #flag为了标记“出现回车但前面不为d”的位置
for i in range(len(newstring)):
if newstring[i] == '\n' and newstring[i-1] != 'd':
flag = i
# print('%s' % newstring[flag-4:flag])#输出需要的字符串
break #退出循环体for
str_new = list(newstring)#字符串转列表
str_new.insert(flag,jobdone)
with open('111.txt','w+') as f:# 打开文件
print('文件重新打开')
f.writelines(str_new)
f.close()
print("文件更新完成并关闭")
def readcount() :
path = os.getcwd() #获取当前绝对路径
# path = os.path.abspath('.')#获取当前相对路径2
with open((r'%s\\111.txt' % path), 'r+', encoding='utf-8') as rf:#打开当前路径下的111.txt文件,第一个\是转义,第二个\表示本地的路径
contents = rf.read()#读取txt文件内容转化为列表
# print(contents)
newstring =''.join(contents)#列表转字符串
flag = None #flag为了标记“出现回车但前面不为d”的位置
for i in range(len(newstring)):
if newstring[i] == '\n' and newstring[i-1] != 'd':
flag = i
# print('%s' % newstring[flag-4:flag])#输出需要的字符串
break #退出循环体for
str_new = list(newstring)#字符串转列表
return newstring[flag-4:flag]#返回已测试账户
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
testcount = readcount()
print(testcount)
markjobdone()