from sys import argv
script,filename = argv
txt = open(filename)
print "here's your file: %r" %filename
print txt.read()
print "type the filename again:"
file_again = raw_input(">")
txt_again = open(file_again)
print txt_again.read()
- open(filename) 第五行是将整个文件赋值给了txt
- read([size])read可以读 [ ]字节 它范围为字符串对象
- 函数与方法(read)都是已经封装好的功能 “但是方法是需要通过对象来调用的,表示针对这个对象要做的操作,使用时采用点方法”(?)
- 不懂第七题怎么直接用命令行打开一个文件
- close()关闭一下