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:
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.
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()
Ada Log Ena Blue