from sys import argv
script,filename = argv
txt = open(filename)//从命令行参数获取文件名
print("Here's your file %r:" %filename)#%r
print(txt.read())
print("I'll also ask you to type it again:")
file_again = input(">")#二次读取,从程序内部输入文件名
txt_again = open(file_again)
print(txt_again.read())
从上篇文章,学过了命令行的使用方法,上段代码中从命令行中获取到文件的名字,通过open("filename")来打开文件,txt.read()方法来读取文件中的内容。