首页 > 代码库 > ex15

ex15

 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 ("make sure your type is right?")
10 makesure = input("Y/N\n>>>>")
11 
12 if makesure == "Y":
13   print (txt.read())
14   print ("you successed!")   #打开文件并在屏幕显示阅读
15   print ("need to close the txt?")
16   closeit = input("ok/no\n>>>>")
17   if closeit == "ok":
18    txt.close()
19   else:
20    print ("read it quickly!")
21    
22 
23 elif makesure == "N":
24   print ("Type the filename again:")  #提示再次输入您的文件名
25   file_again = input("\n>>>>")  #输入您的文件名
26   txt_again = open(file_again)  # 再次定义tex_again为打开您的文件
27   print (txt_again.read())   
28   print ("you successed!") 

 

ex15