<Python编程:从入门到实践>读书笔记 1.读取文件并且对文件内容进行打印有三种方式: with open('test.txt') as fo: for lins in fo: print(lins.rstrip()) with open('test.txt') as fo: lines=fo.read() print(lines.rstrip()) with open('test.txt') as fo2: lt=fo2.readlines() for l in lt: print(l.…
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: …
Python读取txt文件,有两种方式: (1)逐行读取 data=open("data.txt") line=data.readline() while line: print line line=data.readline() (2)一次全部读入内存 data=open("data.txt") for line in data.readlines(): print line…
python 读取中文文件后,作为参数使用,经常会遇到乱码或者报错asii错误等. 我们需要对中文进行decode('gbk') 如我有一个data.txt文件有如下内容: 百度 谷歌 现在想读取文件中内容构建查询语句代码如下: f=open('data.txt','r') for i in f.readlines(): data_line=i.strip() data=data_line.decode("gbk") print "this is %s"%data…