175 except Exception as e:
176 await v_url.client.send_message(
177 v_url.chat_id,
178 "{} caused `{}`".format(caption_rts, str(e)),179 )
180 continue
181 os.remove(single_file)
231 except Exception as e:
232 await v_url.client.send_message(
233 v_url.chat_id,
234 "{} caused `{}`".format(caption_rts, str(e)),235 )
236 continue
237 os.remove(single_file)
256 """
257 for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
258 if num < 1024.0:
259 return "%3.1f %s" % (num, x)260 num /= 1024.0
261
262
272 """
273 for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
274 if num < 1024.0:
275 return "%3.1f %s" % (num, x)276 num /= 1024.0
277
278
56 await event.edit("{}\nFile Name: `{}`\n{}".format(
57 type_of_ps, file_name, tmp))
58 else:
59 await event.edit("{}\n{}".format(type_of_ps, tmp)) 60
61
62def humanbytes(size):
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} ¤"