#!usr/bin/python
# -*-coding:utf-8-*-
from sys import argv
script, filename = argv
#获取参数 给script赋值ex15.py filename赋值ex15_sample.txt
txt = open(filename)
#打开 ex15_sample.txt文本
print ("Here's your file %r:" % filename)
#打印 Here's your file ex15_sample.txt
print (txt.read())
#打印 ex15_sample.txt文本内容
print ("I'll also ask you to type it again:")
#打印 I'll also ask you to type it again:
file_again = input("> ")
#输入为file_again赋值
txt_again = open(file_again)
#打开file_again文本
print (txt_again.read())
#打印file_again文本
运行结果如下:
python ex15.py ex15_sample.txt
Here's your file '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.
Type the filename again:
> ex15_sample.txt
This is stuff I typed into a file.
It is really cool stuff.
Lots an