MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / format_string

Function format_string

tools/python-3.11.9-amd64/Lib/locale.py:213–248  ·  view source on GitHub ↗

Formats a string in the same way that the % formatting would use, but takes the current locale into account. Grouping is applied if the third parameter is true. Conversion uses monetary thousands separator and grouping strings if forth parameter monetary is true.

(f, val, grouping=False, monetary=False)

Source from the content-addressed store, hash-verified

211 return formatted
212
213def format_string(f, val, grouping=False, monetary=False):
214 """Formats a string in the same way that the % formatting would use,
215 but takes the current locale into account.
216
217 Grouping is applied if the third parameter is true.
218 Conversion uses monetary thousands separator and grouping strings if
219 forth parameter monetary is true."""
220 percents = list(_percent_re.finditer(f))
221 new_f = _percent_re.sub('%s', f)
222
223 if isinstance(val, _collections_abc.Mapping):
224 new_val = []
225 for perc in percents:
226 if perc.group()[-1]=='%':
227 new_val.append('%')
228 else:
229 new_val.append(_format(perc.group(), val, grouping, monetary))
230 else:
231 if not isinstance(val, tuple):
232 val = (val,)
233 new_val = []
234 i = 0
235 for perc in percents:
236 if perc.group()[-1]=='%':
237 new_val.append('%')
238 else:
239 starcount = perc.group('modifiers').count('*')
240 new_val.append(_format(perc.group(),
241 val[i],
242 grouping,
243 monetary,
244 *val[i+1:i+1+starcount]))
245 i += (1 + starcount)
246 val = tuple(new_val)
247
248 return new_f % val
249
250def format(percent, value, grouping=False, monetary=False, *additional):
251 """Deprecated, use format_string instead."""

Callers 1

_testFunction · 0.85

Calls 7

listFunction · 0.85
tupleClass · 0.85
_formatFunction · 0.70
subMethod · 0.45
groupMethod · 0.45
appendMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected