python读取txt文档

python读取txt文档

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
def ioHandle(input_file):
    students = []
    # 判断 inform.txt 文件是否存在,
    # 如果存在 inform.txt文件在执行下一步,
    # 如果不存在进行提示并结束程序
    rs = os.path.exists(input_file)
    if rs == True:
        file = open(input_file)
        for line in islice(file, 1, None):
            tmp = line.split()
            students.append(Student(tmp[0],tmp[1],tmp[2],tmp[3]))
        return students
    else:
        print("请检查 inform.txt 文件是否存在")
        os._exit(0)