一般采用显示关闭文件:
f = open('./weibo.py','r')
print f.read()
f.close()
with open('./weibo.py') as f:
for line in f:
print line
退出with代码块时文件自动关闭,不需显示关闭。
一般采用显示关闭文件:
f = open('./weibo.py','r')
print f.read()
f.close()
with open('./weibo.py') as f:
for line in f:
print line
退出with代码块时文件自动关闭,不需显示关闭。
转载于:https://www.cnblogs.com/happywindscq/p/4554595.html