I’ve been using excel to create .csv workesheets that I’d like to parse using python. Each worksheet is named after a shop (e.g worksheet 1: “Waitrose”, worksheet 2: “Tesco”, worksheet 3: “Asda”) and contains a list of products (column 1) and their associated prices (column 2). I’ve written a python script that can access a worksheet and turn the contents into a dictionary (see below) but am struggling to find a way to get the program to access the next worksheet in the workbook. I want to end up with as many dictionaries as worksheets. The csv module doesn’t seem to be of much help and I can’t find a current third party python 3-compatible module that deals with excel. I was thinking maybe applescript but am not sure how I’d embed this in a python script
waitrose = {‘apples’ : 25, ‘oranges’ : 45 etc}
any suggestions?
paul.
Each worksheet must be saved as a separate CSV. Since you are already able to parse a single CSV I’ll concentrate on handling the individual files. Once you have a CSV for each Excel worksheet, you can iterate through each
.csvfile in a directory using theglobmodule. Withglob.glob()you can use wildcards in the path, so if you want just the.csvfiles in a directory use the*.csvwildcard.