try:
out = open('hosts', 'a')
print("hello exam_BIF_1", file=out)
except IOError:
print('IOERROR!')
finally:
out.close()
#######
# 使用with语句改造上面的代码
#不再需要finally语句
try:
with open('hosts', 'a') as datafile:
print("it\'s...", file=datafile)
except IOError as err:
print('file error!' + str(err))