My function returns empty list while I try to import data from csv file

  csv, function, list, python

I want to create a function to search for a composer by name in the given dataset.
and return a list of the appropriate “BL record IDs” related to one composer. Below is my code, however, after running it I get an empty list…

def ComposerSearch(filename, composer_column, name_search, record_id):
     import csv

     ids_list = []

     with open(filename, newline = '', encoding = 'utf-8-sig') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
           if name_search in row[composer_column] and record_id in row[composer_column]:
             ids_list.append(row[record_id])

     return ids_list

name_search = input("Enter Composer's name: ")
ComposerSearch('bl_printed_music_500.csv', 'Composer', name_search, 'BL record ID')

Source: Python Questions

LEAVE A COMMENT