# for read and write, use MyProject_v2 #3 alternative. # ***** Add . (period) to the header that will be automatically assigned or will not use the list to select (e.g. note) print 'succeed' print '' import csv read_file = open("today2.csv", "rU") # make this as a master csv file. overwrite each time. ***make a copy of final csv file as a log read_table = csv.reader(read_file) #*** store headers column_headers = read_table.next() #print column_headers #print list column_header_list_dict = {} column_header_list_count = 0 column_header_dict = {} column_header_count = 0 for i in column_headers: #print i column_header_list_dict[i] = column_header_list_count column_header_list_count = column_header_list_count +1 #print i #print individual header column_header_count = column_header_count +1 column_header_dict[column_header_count] = i print column_header_list_dict print column_header_dict #print dictionary of headers #print column_header_dict[1] #print 1st header print '' print '' # list as a total spreadsheet total_list = [] #list.append(column_headers) # make a list of table *** fix later #*** add list+[] when line8 is deleted for row in read_table: #print row total_list.append(row) print total_list #print total_list[0][3] print'' print '' #4 read values in column and store as dictionary #print column_header_dict # make a copy of column header dictionary row_dict_matrix = column_header_dict.copy() #print total_list for i in column_header_dict: #print i #>>> 1 2 3 4... header_number = column_header_list_dict[column_header_dict[i]] #print header_number row_count = 0 row_dict_matrix[i] = {0: 'add new'} for column in total_list: row = column[header_number] #print row #>>> ibpA ibpB... #print row_dict_matrix[i] if row != '': if row not in row_dict_matrix[i].values(): row_count = row_count +1 row_dict_matrix[i] [row_count] = row print row_dict_matrix #print column_header_dict #4 write new row by selecting from dictionaries #print total_list # count how big the list is but ID# should be +1 from previous number and not the size of the list +1. #print total_list[-1][0] # ID number in the last entry. print '' print'' #total_list.append([]) new_entry_list = [] counter = 0 while counter < len(column_header_dict): counter = counter +1 #print counter column_header_name = column_header_dict[counter] #print column_header_name if '.' not in column_header_name: # takes only the numbers print 'Type the number from the selection for ' + column_header_name + ': ' print row_dict_matrix[counter] select_number = input() if select_number == 0: # add new new_entry_list.append('') print new_entry_list elif 0 < select_number and select_number < len(row_dict_matrix[counter]): # if selected number is in dictionary, enter selected value new_entry_list.append(row_dict_matrix[counter][select_number]) print new_entry_list else: # if entered number is not in the list (bigger number), skip entry print 'work?' else: new_entry_list.append('') # add empty string to the section for autofilling. modify this string later #******** use str(number) to make numbers to strings. this way, you can use '0' and '00' #******** a = [1,2,3,4,5] print a[::-1] returns [5,4,3,2,1]
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question