「Python」テキストファイルの読み込みを行う方法まとめ

方法1
f = open(“zhang.txt”)
line = f.readline()
while line:
print line,
# print(line, end = ”)
line = f.readline()
f.close()

方法2
for line in open(“changfa.txt”):
print line,

方法3
f = open(“d:\\infodemo.txt”,”r”)
lines = f.readlines()
for line in lines
print line