65def test_simple(month):
66 """Can we walk before we run."""
67 text = (
68 "KCVG DS 24/%02i 590353/ 312359// 53/ 48/" 69 "/9470621/T/T/00/00/00/00/00/00/"
70 "00/00/00/00/00/00/00/00/00/00/00/00/00/00/00/00/00/225/26381759/"
71 "26500949="
392 sig.ets.strftime("%H%M"),
393 )
394 channels = ["SIGMET.%s" % (i,) for i in sig.centers]
395 channels.append("SIGMET.%s" % (self.source[1:],))396 xtra = {"channels": ",".join(channels), "twitter": txt}
397
398 j.append([txt, html, xtra])
391 area,
392 sig.ets.strftime("%H%M"),
393 )
394 channels = ["SIGMET.%s" % (i,) for i in sig.centers]395 channels.append("SIGMET.%s" % (self.source[1:],))
396 xtra = {"channels": ",".join(channels), "twitter": txt}
397
385 area,
386 sig.ets.strftime("%H%M"),
387 )
388 html = ("<p>%s issues SIGMET %s%s till %s UTC</p>") % (389 self.source,
390 sig.label,
391 area,
379 j = []
380 for sig in self.sigmets:
381 area = " for " + sig.areatext if sig.areatext != "" else ""
382 txt = ("%s issues SIGMET %s%s till %s UTC") % (383 self.source,
384 sig.label,
385 area,
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} ¤"