每日总结2024/1/17

原文地址::https://blog.csdn.net/weixin_44925499/article/details/103597654?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

 

相关文章

1、提取TXT文本中指定内容——python----https://blog.csdn.net/weixin_44409075/article/details/88080091

2、python提取具有某种特定字符串的行数据----https://blog.csdn.net/u011436427/article/details/82628597?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~first_rank_v2~rank_v28-1-82628597.nonecase&utm_term=python%E6%8F%90%E5%8F%96%E6%96%87%E4%BB%B6%E4%B8%80%E8%A1%8C%E4%B8%AD%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2&spm=1000.2123.3001.4430

3、个人整理Python代码实例----https://www.cnblogs.com/huigebj/p/11295202.html

用python实现关键字提取内容,用于初学者
在这里先将关键字存放再文件中1.txt,需要读取的内容再2.txt中,最后提取出来的内容存放在3.txt中。
代码如下:

 
 
f = open('1.txt','r',encoding='utf-8')
q = open('3.txt','a+',encoding='utf-8')
line1 = f.readlines()
for l in line1:
    p = open('2.txt', 'r', encoding='utf-8')
    line2 = p.readlines()
    for ll in line2:
       # print(ll)
        if l.strip() in ll:
           # print(ll)
           # print(l)
            #print(l.strip())
            q.writelines(ll)
    p.close()
f.close()
q.close()

 

posted @ 2024-01-18 00:00  橘子味芬达水  阅读(20)  评论(0)    收藏  举报