美文网首页
练习15 读取文件

练习15 读取文件

作者: 黑色茄子 | 来源:发表于2017-09-16 14:04 被阅读0次

这节练习 包括两部分
txt 文件部分 (文件名 : ex15_sample.txt)
This is stuff I typed into a file.
It is really cool stuff.
Lots and lots of fun to have in here.

py部分
from sys import argv

script,filename = argv #定义传入参数

txt = open(filename) #打开txt文件

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

相关文章

网友评论

      本文标题:练习15 读取文件

      本文链接:https://www.haomeiwen.com/subject/qkgysxtx.html