问题代码如下 links = open("new") out = open("out.txt","w+") for link in links: out.write(link+"\n") 问题原因: 当没有使用flush()或close()时,要写入的内容依然在缓冲区中,没有写入文件,如果中途终止,文件里就会没有内容. 解决方法: links = open("new") out = open("o
知识点不多 一:普通操作 # rt 模式的 open() 函数读取文本文件 # wt 模式的 open() 函数清除覆盖掉原文件,write新文件 # at 模式的 open() 函数添加write新文件 with open("../../testData","rt",encoding="utf-8") as f : for line in f : print(line) # 写操作默认使用系统编码,可以通过调用 sys.getdefaulte
Python 读取写入配置文件 —— ConfigParser Python 读取写入配置文件很方便,可使用内置的 configparser 模块:可查看源码,如博主本机地址: “C:/python27/lib/configparser.py” Configuration file parser. A setup file consists of sections, lead by a "[section]" header, and followed by "name: