返回顶部

收藏

Define function to Open a file

更多
import sys

def open_file(file_name, mode):
    '''Open a file.'''
    try:
        the_file = open(file_name, mode)
    except(IOError), e:
        print 'Unable to open the file', file_name, 'Ending program.\n', e
        raw_input('\n\nPress the enter key to exit.')
        sys.exit()
    else:
        return the_file

trivia_file = open_file('trivia.txt', 'r')

标签:Python,File

收藏

0人收藏

支持

0

反对

0

发表评论