一.python文件读取 1.基本操作 读取文件信息时要注意文件编码,文件编码有UFT-8.ASCII或UTF-16等. 不过在python中最为常用的是UTF-8,所以如果不特别说明就默认UTF-8编码. 读取文件可以使用 rt 模式下的 open()函数,示例如下: #以字符串的形式读取一个文件 with open('somefile.txt', 'rt') as f: data = f.read() with open('somefile.txt', 'rt') as f: for lin…
1.如何将一个“lessons.txt”文档一行行输出? myfile = file(‘lessons.txt’) for f in myfile.readlines(): print f myfile.close() #-*- coding:utf-8 -*- file_path = "C:\\Users\\Administrator\\workspace\\template.txt" with open(file_path,'r') as f: lines = f.readline…