Creating a list using the last element of each line in a text file

I’m a bit of a newbie in programming. Currently I’m trying to create lists by reading a text file. Also without importing any modules. A piece of the text file is:

ABC101,Lecture,Monday,08:00,10:00,Jenolan,J10112,Ada Log
ABC101,Tutorial,Tuesday,10:00,11:00,Jenolan,J10115,Ena Blue

I basically want to put each category into their own list.

This is how I started:

def lecturer():
    lecturer_info = open('timetables.txt', 'r')
    line = lecturer_info.readline().split(',')

    while line != '':
        lecturer_info = line.split(',')
        full_name = lecturer_info[-1].split()

    print('full_name') 

But I’m currently getting an error… “lecturer_info = line.split(‘,’) AttributeError: ‘list’ object has no attribute ‘split’.

Any ideas on how to fix this, or an alternate way to do it. Thanks.

Answer

Here is a solution that is close to yours with some corrections:

def lecturer():
    lecturer_info = open('timetables.txt', 'r')
    lines = lecturer_info.readlines()

    for line in lines:
        lst = line.strip().split(',')
        full_name = lst[-1]
        print(full_name)

    lecturer_info.close()

output:

Ada Log
Ena Blue