文件处理 将txt文件当中数据取出进行以邮箱分类处理 将邮箱拿出来写入对应的文件夹 分文件夹进行存储 新手求吐槽优化



import os
pathemail = r'E:\python\7.11\邮箱.txt'
with open(pathemail,'r',encoding='utf-8') as f:
    flist = f.readlines()
    for i in range(len(flist)):
        a = flist[i].split('@')
        b = a[1].split('.')
        path =r'E:\python\7.11\邮箱'+ '\\' +b[0]
        if os.path.isdir(path):
            op = open(path + '\\' + b[0] + '.txt','a',encoding='utf-8')
            op.write(flist[i])
        else:
            os.mkdir(path)

猜你喜欢

转载自blog.csdn.net/weixin_39365429/article/details/81080668