I am trying to open a worksheet in XL. The worksheet could be named as ‘Map’, ‘map’ or ‘MAP’
This is what I am doing
import xlrd
book = xlrd.open_workbook(xls) // where xls is the name of the spreadsheet
try:
sheet = book.sheet_by_name('map')
except:
try:
sheet = book.sheet_by_name('Map')
except:
try:
sheet = book.sheet_by_name('MAP')
except:
raise
This looks pretty clunky… is there a more pythonic way of doing this
While it is not exactly as readable as some other methods, probably the shortest way is to use:
Basically, this uses the concept of list intersection presented via another SO answer. Probably an easier way to create this so it easier to read: