def listurl(path,encode="UTF-8-sig"): list_l = [] with open(path, 'r', encoding=encode) as r: while 1: red = r.readline().split("\n")[0] L.append(red) if not red: break list_l = [x for x in L if x != ''] return list_l |
在 if 判断中有点不严谨但是一般情况是够用的 如果不够用可以稍微修改下

标题:Python 常用代码 打开文件操作(1)
作者:昊辰SEO优化
链接:https://www.luohao2.com/bianchengjiaocheng/53.html
声明:本文为成都昊辰SEO优化原创,如需转载请联系作者,2642657068