读文件
- 输入:
# -- coding: utf-8 --
from sys import argv
script, filename = argv
txt = open(filename) ##将打开的对象赋值
print "Here's your file %r:" % filename
print txt.read() ##读取txt的内容
##下面是用raw_inpu()的方法来读取文件
print "Type the filename again:"
file_again = raw_input("> ")
txt_again = open(file_again)
print txt_again.read()
-
运行: