#!/usr/bin/env python

'readtextfile.py -- read and display text file'

#get filename
fname=raw_input('Enter filename: ')
print

#attempt to open file for reading
try:
    fobj=open(fname,'r')
except IOError,e:
    print "*** file open error:",e
else:
    #display contents to the screen
    for eachLine in fobj:
        print eachLine
    fobj.close()

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐