代码如下:

 1 #coding:utf-8
 2 from sys import argv 
 3 
 4 script, filename = argv 
 5 
 6 txt = open(filename) #将打开的文件内容赋值给变量txt
 7 
 8 print "Here's your file %r:" % filename 
 9 print txt.read() #读取txt的内容
10 
11 print "Type the filename again:"
12 file_again = raw_input("> ") #玩家输入新文件的文件名,并且将文件名赋值给file_again
13 
14 txt_again = open(file_again) #将新文件打开,并将新文件内容赋值给txt_again
15 
16 print txt_again.read() #读取txt_again的内容
17 
18 txt.close()
19 txt_again.close()

运行结果: 
这里写图片描述

posted on 2017-10-10 22:25  讲道理好嘛  阅读(182)  评论(0编辑  收藏  举报