码迷,mamicode.com
首页 > 其他好文 > 详细

笨办法15读取文件

时间:2017-10-10 23:13:13      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:odi   color   from   csdn   文件名   input   south   赋值   water   

代码如下:

 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()

运行结果: 
技术分享

笨办法15读取文件

标签:odi   color   from   csdn   文件名   input   south   赋值   water   

原文地址:http://www.cnblogs.com/p36606jp/p/7648174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!