Chinaunix

标题: 文件读取和显示 readtextfile.py [打印本页]

作者: zhengsenlin888    时间: 2009-10-29 16:15
标题: 文件读取和显示 readtextfile.py

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


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103983/showart_2082182.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2