《笨办法学 Python 3.0 documentation》习题16

近期,一直在努力学习py3.0,因为自己有编程语言的基础,相对来说,学习效率和速度应该还算可以,但是有些知识点是自己常犯的错误,所以特意做一个系列来进行学习,将自己易错的内容提醒自己:

以下练习16  读写文件

from sys import argv
script, filename=argv
print("We are going to reading your file %r.") % filename
target =open(filename,'rw') #读写权限要注意
line=target.read()  
print "Read txt: %r" %(line)

print "Finally , we close it."
target.close()

此次练习,要注意文件权限要开放r,如只有w权限的话,程序仍然无法打开文件。

猜你喜欢

转载自blog.csdn.net/qq_29855509/article/details/121601553