python - tkinter optionmenu looking up excel list -
i have optionmenu working ok looking list in code if list maintained externally in excel file. how go looking excel file, called....vehicles.xlsx , list in column a? use pandas or there ther existing option within python working code below want rid of list , replace excel lookup.
sorry in advance if there tutorial somewhere can't seem find , i'm pretty new python.
thanks
self.cars=["car1","car2"] self.installin = tk.optionmenu(self,self.var,*self.cars).grid(row=4,column=2,sticky=tk.w, padx=8, pady=8)
checking out excel 2003, seems can save spreadsheets xml
, txt
, csv
among others.
not sure how text file look, i'd start might save library import (xml, csv), in case that's consideration.
edit: in case isn't, check out csvs' dictreader, believe it's quickest solution.
if like/prefer work json, can convert csv json few lines of code.
edit 2: extracting first column csv file may this:
import csv open('install.csv') csvfile: # generating dictreader object reader=csv.dictreader(csvfile) # contain values in 1st column first_col=[] # assuming first column titled 'ins' , skipping empty cells first_col.extend([row['ins'] row in reader if row['ins']])
alternatively, if didn't name columns, can use csv.reader
. relevant part looks this:
reader=csv.reader(csvfile) # instead of csv.dictreader(csvfile) first_col=[] first_col.extend([row[0] row in reader if len(row) , row[0]])
Comments
Post a Comment