python读取和显示txt文件
#!/usr/bin/env python'readtextfile.py -- read and display text file'#get filenamefname=raw_input('Enter filename: ')print#attempt to open file for readingtry: fobj=open(fname,'r')ex
·
#!/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()
更多推荐
已为社区贡献1条内容
所有评论(0)