尝试脚本的第一天

# 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()
自动切换账号及修改本地txt文档
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值