460 word_separator = separator
461
462 estimated_size = pretty_size(productor.total_size(sep=word_separator))
463 print(("estimated display size: %s, generate dict...") % (estimated_size))464
465 if not os.path.exists(
466 os.path.abspath(os.path.join(output, os.path.pardir))):
421 word_count, word_size = get_string_array_rule_data_size(rule)
422 word_count_list.append(word_count)
423 if word_size < 0:
424 echo("skip calculate StringArrayRule size, rule: %s" % (rule.raw_rule))425 word_size_list.append(0)
426 else:
427 word_size_list.append(word_size)
388 # empty string, skip insert
389 insert_index += 1
390 else:
391 echo("found normal string: %s" % (string_rule))392 string_array_rule = StringArrayRule(string_rule, 1, 1, [string_rule], global_repeat_mode)
393 rules.insert(insert_index, string_array_rule)
394 insert_index += 2
364 echo("invalid min_repeat: %d or max_repeat: %d, rule: %s" % (min_length, max_length, match[0]))
365 return None
366 if max_length > len(expanded_char_array):
367 echo("rule '%s' is invalid, max_repeat(%d) cannot be greater than the size of char_array(%d)!"368 % (match[0], max_length, len(expanded_char_array)))
369 return None
370 char_array_rule = CharArrayRule(match[0], min_length, max_length,
361 min_length = max_length = 1
362 if min_length < 0 or max_length < 0 or min_length > max_length \
363 or (min_length == 0 and max_length == 0):
364 echo("invalid min_repeat: %d or max_repeat: %d, rule: %s" % (min_length, max_length, match[0]))365 return None
366 if max_length > len(expanded_char_array):
367 echo("rule '%s' is invalid, max_repeat(%d) cannot be greater than the size of char_array(%d)!"
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} ¤"