广告关闭
腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元!
if line.split(): print(idx, line)r_file.close()打印结果:0 hello2 nanjing4 100...
版权声明:本文为博主原创文章,遵循 cc 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https:blog.csdn.netgithub_39655029articledetails88692024 功能读取存在空行的文件,删除其中的空行,并将其保存到新的文件中; 代码#! usrbinenv python# -*- coding: utf-8 -*-# @time : 2019318 21:41# ...
strings 和 stripped_strings 属性 如果 tag 中包含多个字符串,可以用 strings 属性来获取。 如果返回结果中要去除空行,则可以用 stripped_strings 属性。 soup = beautifulsoup( test 1 test 2 , html.parser) element =soup.div.stripped_strings print(list(element)) # 2、父节点parent属性 parent 属性返回某...
usrbinpythonimport ref1 = open(tmptest.txt)f2 = open(tmpmyhello.txt,r+)for sin f1.readlines():f2.write(s.replace(hello