I was just curious what the use of flushing would be in this particular instance, as it has no bearing on whether my app functions or not. The line in question is under the 2nd class Route definition, the "sys.stdout.flush()" line. What would that be used for?
class Route(object):
def __init__(self):
self.__route = [] #route information array
def add_route(self, t): #user generated input array
self.__route.append(t)
print t.name
sys.stdout.flush() #using "flush" method
def compile_list(self): #route list compiler
output = "" #sets addition variable
for route in self.__route: #looping inputs
output += "<div id='container'><div class='results-container'><span class='title'>Route name: </span>" + "<span class='result'>" + route.name + "</span></div><br />" + "<div class='results-container'><span class='title'>Stop One: </span>" + "<span class='result'>" + route.stop_one + "</span></div><br />" + "<div class='results-container'><span class='title'>Stop One Mileage: </span>" + "<span class='results-container'>" + route.stop_one_mileage + "</span></div><br />" + "<div class='results-container'><span class='title'>Stop Two: </span>" + "<span class='results-container'>" + route.stop_two + "</span></div><br />" + "<div class='results-container'><span class='title'>Stop Two: </span>" + "<span class='results-container'>" + route.stop_two_mileage + "</span></div><br />" + "<div class='results-container'><span class='title'>Stop Three: </span>" + "<span class='results-container'>" + route.stop_three + "</span></div><br />" + "<div class='results-container'><span class='title'>Stop Three: </span>" + "<span class='results-container'>" + route.stop_three_mileage + "</span></div><br />"
return output #output return
#===================== Calculates the average of all three ==========================
def calc_average(self): #average calculation
stop_one_mileage = self.__route[0].stop_one_mileage #stop_one_mileage average
stop_two_mileage = self.__route[0].stop_two_mileage #stop_two_mileage
stop_three_mileage = self.__route[0].stop_three_mileage #stop_three_mileage
avg = (int(stop_one_mileage) + int(stop_two_mileage) + int(stop_three_mileage))/3 #adds all three and divides by three
return "<div class='results-container'><span class='title'>Average Mileage: </span><span class='results-container'>" + str(avg) + " miles</span></div>" #returns results
#===================== Calculates total of all three ==========================
def calc_total(self): #calculates the total of all three
stop_one_mileage = self.__route[0].stop_one_mileage #stop_one_mileage
stop_two_mileage = self.__route[0].stop_two_mileage #stop_two_mileage
stop_three_mileage = self.__route[0].stop_three_mileage #stop_three_mileage
total = int(stop_one_mileage) + int(stop_two_mileage) + int(stop_three_mileage) #sets total of all three input
return "<div class='results-container'><span class='title'>Total Mileage: </span><span class='results-container'>" + str(total) + " miles</span></div>" + "</div>" #returns results
class FormData(object): #form data object
def __init__(self):
self.name = ""
self.stop_one = ""
self.__stop_one_mileage = "" #makes sure mileage isn't zero
self.stop_two = ""
self.stop_two_mileage = "" #makes sure mileage isn't zero
self.stop_three = ""
self.stop_three_mileage = "" #makes sure mileage isn't zero
#===================== Getter/Setter ==========================
@property #stop_one_mileage getter
def stop_one_mileage(self):
return self.__stop_one_mileage #returns the stop_one_mileage
@stop_one_mileage.setter #stop_one_mileage setter
def stop_one_mileage(self, m):
if m <= 0:
self.__stop_one_mileage = 10 #mileage set to 10 (nice round number)
else:
self.__stop_one_mileage = m #returns a value as long as the input is more than zero