# fix the following code data = 'a,b,c' + '\n' + 'd,e,f' items = data.split('\n').split(',') # fix this # list doesn't have split, the first split('\n') results in a list of string # can't call split on list, but can iterate over a list and split list's element # items = data.split('\n') # solution print(items) for item in items: print('-->', item.split(',')) file_content = open('data.csv').read() print(file_content) file_content = open('data.csv').read().split('\n') # result in a list print('file_content =', file_content) # file_content = open('data.csv').read().split('\n').split(',') # crash -- try to split a list -- list doesn't have split attribute # print(file_content) file_content = str(open('data.csv').read().split('\n')) print(file_content) print(type(file_content)) # not crash -- get item in a list, split by ',' print('now split the string -->', file_content.split(',')) # the following code produces the same output as above file_content = str(open('data.csv').read().split('\n')).split(',') print('convert list to string, then split -->', file_content) # to split items in each line file_content = open('data.csv').read().split('\n') result_list = [] for item in file_content: result_list.append(item.split(',')) print(result_list)