import csv # create two lists position_list=[1,2,3,4] special_list=["fred", "jane", "jim"] # write each list to separate csv file with open('SpecialFile.csv', 'w') as specialfile: # opens/creates file, creates "specialfile" to store the data for the file special_file=csv.writer(specialfile) # special_file variable aasigned to connect to specialfile special_file.writerow (special_list) # places the list into the special_file # when WITH terminates file is closed with open('PositionFile.csv', 'w') as positionfile: position_file=csv.writer(positionfile) position_file.writerow (position_list) # erase the original lists position_list=[] special_list=[] print(special_list) print(position_list) # ------ Take contents out of PositionFile.csv and SpecialFile.csv and put them back into lists---------------# with open('SpecialFile.csv', 'r') as specialfile: # opens file and connects it to "specialfile" special_list = csv.reader(specialfile) # contents of specialfile placed into variable special_list special_list= [row for row in special_list] # special_list contents read as list items (assuming multiple rows) special_list=special_list[0] # only first row kept with open('PositionFile.csv', 'r') as positionfile: # uses the reader method position_list = list(csv.reader(positionfile)) position_list= [row for row in position_list] position_list=position_list[0] # at this point list items are strings for item in range (0,len(position_list)): # process list to convert strings to integers position_list[item] = int(position_list[item]) print(special_list) print(position_list)