358
359 # Risky rivers
360 warning_text2 = Div(
361 text="""<p><b>{}</b> rivers with stations at risk, the top 5 is tabulated below.</p>""".format(362 len(rivers_with_station(risky_stations))
363 ),
364 width=600,
415 )
416 )
417 warning_text3 = Div(
418 text="""<p><b>{}</b> clusters found, the towns within these clusters419 (<b>{}</b> in total) have a high risk of flooding.
420 The table below lists the towns with the highest relative water level
421 within each cluster in the order of decreasing risk
544 predict_plot.sizing_mode = "scale_width"
545 predict_plots.append(Panel(child=predict_plot, title=station.name))
546 predicting_text = Div(
547 text="<p><i>Prediction is running... {:.0%}</i></p>".format(i / 6)548 )
549 doc.add_next_tick_callback(
550 partial(
75 d += " coordinate: {}\n".format(self.coord)
76 d += " town: {}\n".format(self.town)
77 d += " river: {}\n".format(self.river)
78 d += " typical range: {}".format(self.typical_range) 79 return d
80
81 def typical_range_consistent(self):
69 return self._town
70
71 def __repr__(self):
72 d = "Station name: {}\n".format(self.name) 73 d += " id: {}\n".format(self.station_id)
74 d += " measure id: {}\n".format(self.measure_id)
75 d += " coordinate: {}\n".format(self.coord)
f-strings are the fastest way to format strings as compared to the following methods:
%
format()
str.join
+
operator to concatinate stringTemplate.substitute
Some less preferred ways to format strings are the following:
from string import Template
menu = ('eggs', 'spam', 42.4)
old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string]
beginner_order = menu[0] + " and " + menu[1] + ": " + str(menu[2]) + " ¤"
joined_order = " and ".join(menu[:2])
format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2])
named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2])
template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2])
Consider using f-strings as shown below:
menu = ('eggs', 'spam', 42.4)
f_string_order = f"{menu[0]} and {menu[1]}: {menu[2]:0.2f} ¤"