Subject explains it, or ask.
This is a bloody mess:
' 123,456,789's = "123456789" # arrives as str
f"{f'{int(s):,}': >20}"
' 123,456,789's = "123456789"
f'{int(s): >20,}'
' 123,456,789'f'{int(s):20,}'
Subject explains it, or ask.
This is a bloody mess:
' 123,456,789's = "123456789" # arrives as str
f"{f'{int(s):,}': >20}"
' 123,456,789's = "123456789" # arrives as str
s_int = int( s ) # makes the transformation obvious and distinct
s_format = ">20," # define how the value should be presented
F"{s_int:{s_format}}"
S_FIELD_WIDTH = 20
s_format = F">{S_FIELD_WIDTH},"
RIGHT_JUSTIFIED = ">"
THOUSANDS_SEPARATOR = ","
s_format = F"{RIGHT_JUSTIFIED}{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
s_format = F"{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
and if we really want to go over-board:
RIGHT_JUSTIFIED = ">"
THOUSANDS_SEPARATOR = ","
s_format = F"{RIGHT_JUSTIFIED}{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
or (better) because right-justification is the default for numbers:
s_format = F"{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
To the extreme that if your user keeps fiddling with presentations (none
ever do, do they?), all settings to do with s_format could be added to a config/environment file, and thus be even further separated from program-logic!
On 2024-08-26 at 20:42:32 +1200,
dn via Python-list <python-list@python.org> wrote:
and if we really want to go over-board:
RIGHT_JUSTIFIED = ">"
THOUSANDS_SEPARATOR = ","
s_format = F"{RIGHT_JUSTIFIED}{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
or (better) because right-justification is the default for numbers:
s_format = F"{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"
To the extreme that if your user keeps fiddling with presentations (none
ever do, do they?), all settings to do with s_format could be added to a
config/environment file, and thus be even further separated from
program-logic!
And then you'll need a parser, many of whose Unique Challenges™ aren't
even apparent until you start parsing files from actual users, and
you'll still need some sort of fallback in the code anyway for the case
that s_format can't be parsed (for whatever reason).
Isn't a config file what just caused the global CrowdStrike outage? ;-)
That said, I understand that report generators are a thing, not to
mention RPG (https://en.wikipedia.org/wiki/IBM_RPG).
Okay, sorry; I'll just crawl back into the hole from whence I came.
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 4 |
Nodes: | 8 (0 / 8) |
Uptime: | 59:12:31 |
Calls: | 65 |
Files: | 21,500 |
Messages: | 73,559 |