标签:
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, score
1302303069, qxj511,98.80
1302303070, zhy,99.90
依次读取:
fd = open("qxj511.txt","r+")
print fd.readline()
print fd.readline()
fd.close()
打印:
ID, name, score
1302303069, qxj511,98.80
fd = 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 st
fd.close()
标签:
原文地址:http://www.cnblogs.com/qxj511/p/4918814.html