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

Function _format_align

tools/python-3.11.9-amd64/Lib/_pydecimal.py:6268–6293  ·  view source on GitHub ↗

Given an unpadded, non-aligned numeric string 'body' and sign string 'sign', add padding and alignment conforming to the given format specifier dictionary 'spec' (as produced by parse_format_specifier).

(sign, body, spec)

Source from the content-addressed store, hash-verified

6266 return format_dict
6267
6268def _format_align(sign, body, spec):
6269 """Given an unpadded, non-aligned numeric string 'body' and sign
6270 string 'sign', add padding and alignment conforming to the given
6271 format specifier dictionary 'spec' (as produced by
6272 parse_format_specifier).
6273
6274 """
6275 # how much extra space do we have to play with?
6276 minimumwidth = spec['minimumwidth']
6277 fill = spec['fill']
6278 padding = fill*(minimumwidth - len(sign) - len(body))
6279
6280 align = spec['align']
6281 if align == '<':
6282 result = sign + body + padding
6283 elif align == '>':
6284 result = padding + sign + body
6285 elif align == '=':
6286 result = sign + padding + body
6287 elif align == '^':
6288 half = len(padding)//2
6289 result = padding[:half] + sign + body + padding[half:]
6290 else:
6291 raise ValueError('Unrecognised alignment field')
6292
6293 return result
6294
6295def _group_lengths(grouping):
6296 """Convert a localeconv-style grouping into a (possibly infinite)

Callers 2

__format__Method · 0.85
_format_numberFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected