摘要: 往文件中所有添加指定的前缀方法一:open方法f_r = open('text.txt')f_w = open('text_new.txt','w+')i = 0while True: i += 1 line = f_r.readline() if not line: break f_w.write('%02d'%i + '.python'+ ' ' +lin... 阅读全文
posted @ 2019-01-21 17:22 阳光宝贝-沐沐 阅读(414) 评论(0) 推荐(0)
摘要: python练习六十一:文件处理,读取文件内容假设要读取text.txt文件中内容写文件(如果有文件,那直接调用就行,我这里自己先创建的文件)list1 = ['python','jave','go','shell','perl']with open('text.txt','w+') as f: for i in list1: f.write(i+'\n')方法一:使用with... 阅读全文
posted @ 2019-01-21 17:09 阳光宝贝-沐沐 阅读(183) 评论(0) 推荐(0)
摘要: 网页分析,找出里面的正文与链接代码如下:from urllib import requestfrom bs4 import BeautifulSouprequest = request.urlopen('https://www.baidu.com/')request_text = request.read().decode('utf-8')soup = BeautifulSoup(request... 阅读全文
posted @ 2019-01-21 10:46 阳光宝贝-沐沐 阅读(210) 评论(0) 推荐(0)