0
点赞
收藏
分享

微信扫一扫

python 把文件中含有xx字符的行写入到一个新文件

山竹山竹px 2022-04-29 阅读 66
python
def openfile(pas):
          with open(pas, 'r', encoding='utf-8') as f:
              text = f.readlines()
          return text
def writefile(pas,s):
    with open(pas, 'a', encoding='utf-8') as f:
        f.write(s)
a = openfile('D:\python\KPI\est.txt')
for i in a:
    if '小明' in i:
        writefile('D:\python\KPI\est2.txt', i)
举报

相关推荐

0 条评论