I'm currently working a project for class and I've gotten stuck. I am suppose to write a program that will read a csv file and create a text file with information from this csv file.
So, far I have code that prompts for the file name and gives a "File not found" message, if the file does not exsist and will prompt over and over again until a vaild file name is entered. What I'm stuck on is a function that I've created to get the values of a certain column into a list. The code is below:
def get_values(file, column_index): '''(str, int) -> list Return a list of values in file at colum_index''' value_list =  for line in file: line_list = line.split('.') value_list.append(line_list[column_index]) return value_list while True: try: file_name = input('Enter in file name: ') input_file = open(file_name, 'r') break except IOError: print('File not found.')
I'm trying to make the code general as possible so that any csv file and column index can be used. When I run the program though, I get an error message for the line "value_list.append(line_list[column_index])". Why is that? I thought using a variable like this was valid.
Thanks for any help.