In my program, I prompt the user to enter a range of cities (in a spreadsheet), and then a range of review scores, and then make some decisions based on what the user has entered. Since the handling of the both user inputs (both ranges) is common to each, I have combined both into the single function getRanges() below. It works well, but I get the sense that can be improved (shortened, and with fewer if/else's). In the absence of a switch statement in Python, what are some neater approaches here?# -*- coding: utf-8 -*-from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import Selectfrom selenium.common.exceptions import NoSuchElementExceptionfrom selenium.common.exceptions import NoAlertPresentExceptionfrom selenium.common.exceptions import ElementNotVisibleExceptionfrom selenium.common.exceptions import WebDriverExceptionimport unittest, time, refrom functions import *from collections import OrderedDictimport csvfrom openpyxl import load_workbookfrom easygui import enterbox, msgboximport tracebackclass bot(unittest.TestCase):    def setUp(self):        self.wb = load_workbook(Spreadsheet.xlsx, data_only=True)        self.cities = []        self.getRanges('cities')        self.getRanges('reviews')        print 'Running...'        try:             self.driver = webdriver.Firefox()        except WebDriverException, e:            print Unable to load profile, retrying            try:                 self.driver = webdriver.Firefox()            except WebDriverException, e:                print Unable to load profile, retrying                self.driver = webdriver.Firefox()        self.driver.implicitly_wait(30)        self.base_url = https://www.google.com/ncr        self.verificationErrors = []        self.accept_next_alert = True        self.reviewPattern = re.compile(ur'\d+')        self.niche = plumbers+    def getRanges(self, citiesOrReviews):        self.LowerLimit = enterbox(Enter a lower limit for %s, or 'all' % citiesOrReviews, 'Range')        if self.LowerLimit.lower().strip(') == all:            self.reviewRange = False            if citiesOrReviews.lower() == 'cities':                for row in self.wb.active.rows:                                     self.cities.append(row[0].value)        elif self.LowerLimit.isdigit():            if citiesOrReviews.lower() == 'cities':                if int(self.LowerLimit) > len(self.wb.active.rows):                    msgbox(The lower limit you've entered is higher than the number of cities in the spreadsheet. Let's retry., 'Error')                    self.getRanges(citiesOrReviews)            self.UpperLimit = enterbox(Enter an upper limit for %s: % citiesOrReviews, Range)            if self.UpperLimit.isdigit():                if citiesOrReviews.lower() == 'cities':                    if int(self.UpperLimit) > len(self.wb.active.rows):                        msgbox(The upper limit you've entered is higher than the number of cities in the spreadsheet. Let's retry., Error)                        self.getRanges(citiesOrReviews)                    if self.UpperLimit <= self.LowerLimit:                        msgbox(The upper and lower limits are identical, or the upper limit is less than the lower. Let's retry., Error)                        self.getRanges(citiesOrReviews)                    else:                        if citiesOrReviews.lower() == 'cities':                            for row in self.wb.active.rows[int(self.LowerLimit) - 1:int(self.UpperLimit)]:                                self.cities.append(row[0].value)                elif citiesOrReviews.lower() == 'reviews':                    self.reviewRange = [int(self.LowerLimit) - 1, int(self.UpperLimit)]        else:            msgbox(The value entered must either be 'all', or a number. Let's retry., Error)             self.getRanges(citiesOrReviews)
Bot that selects web reviews based on spreadsheet entries
python;unit testing;python 2.7;excel;selenium