Python文件读取切割

文件内容,保存到f:/test/2.txt

1 xiejunjie
2 junjiex
3 aaaa
4 bbb
5 cccc


f = open("f:/test/2.txt");
line = f.readline();//行读取
arr = [];
while line:
    print line.split(" ")[1];
    arr.append(line.split(" ")[1]);
    line = f.readline();
f.close();
print "------------"

for s in arr:
    print s;


print "-----------------";
f = open("f:/test/2.txt");
line = f.read();//一次性读取
print line;





你可能感兴趣的:(python,文件)