标签:
readline([size])-> next line from the file, as a string.Retain newline. A non-negative size argument limits the maximum number of bytes to return(an incomplete line may be returned then).Return an empty string at EO内容: ID, name, score1302303069, qxj511,98.801302303070, zhy,99.90依次读取:fd = open("qxj511.txt","r+")print fd.readline()print fd.readline()fd.close()打印: ID, name, score1302303069, qxj511,98.80fd = open("qxj511.txt","r")s = fd.readline() // 读取第一行while s !="": // 判断读取的结果是否为空 s = s.rstrip("\n") // 删除字符串后面的 \n print s // 打印字符串 s = fd.readline() // 重新读取一行fd.close() // 当读取完毕的时候,也就是 readline 返回值为零fd = open("qxj511.txt","r")for st in fd: print stfd.close()标签:
原文地址:http://www.cnblogs.com/qxj511/p/4918814.html