现在的位置: 首页 > 综合 > 正文

文件读取和显示(readTextFile.py)

2018年12月26日 ⁄ 综合 ⁄ 共 276字 ⁄ 字号 评论关闭

输入文件路径,屏幕打印文件内容。

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

抱歉!评论已关闭.