Learn Python From 'Head First Python' [3](1) : Exception

1.the using of exception

2.file opration

import os
>>> try:
    data = open('sketch.txt')
    for each in data:
        try:
            (role,message) = each.split(':')
            print(role + ' says: ' + message, end='')
        except ValueError:
            pass
    data.close()
except IOError:
    print('file is missing')

you can get the sketch.txt from the python offical webstatie

posted @ 2014-09-08 20:16  拙急鸟  阅读(123)  评论(0编辑  收藏  举报