您的位置:首页 > 编程语言 > Python开发

python读取和显示txt文件

2015-10-02 00:32 639 查看
#!/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()

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: