Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: What do you call a blind, deaf-mute, quadraplegic Virginian? A: Trustworthy.


comp / comp.lang.python / Re: Is there a better way? [combining f-string, thousands separator, right align]

SubjectAuthor
* Is there a better way? [combining f-string, thousands separator, right align]Gilmeh Serda
+* Re: Formatting a str as a numberStefan Ram
|`* Re: Formatting a str as a numberStefan Ram
| `* Re: Formatting a str as a numberGilmeh Serda
|  +* Re: Formatting a str as a numberStefan Ram
|  |`- Re: Formatting a str as a numberGilmeh Serda
|  `* Re: Formatting a str as a numberGrant Edwards
|   `* Re: Formatting a str as a numberGilmeh Serda
|    `* Re: Formatting a str as a number - Okay, one more related thing...Gilmeh Serda
|     +* Re: Formatting a str as a number - Okay, one more related thing...Stefan Ram
|     |+* Re: Formatting a str as a number - Okay, one more related thing...Stefan Ram
|     ||+- Re: Formatting a str as a number - Okay, one more related thing...Stefan Ram
|     ||`- Re: Formatting a str as a number (Posting On Python-List Prohibited)Lawrence D'Oliveiro
|     |`- Re: Formatting a str as a number - Okay, one more related thing...Gilmeh Serda
|     +- Re: Formatting a str as a number - Okay, one more related thing...MRAB
|     `- Re: Formatting a str as a number - Okay, one more related thing...dn
+- Re: Is there a better way? [combining f-string, thousands separator, right alignPierre Fortin
+- Re: Is there a better way? [combining f-string, thousands separator, right aligMRAB
+- Re: Is there a better way? [combining f-string, thousands separator, right alignPierre Fortin
+* Re: Is there a better way? [combining f-string, thousands separator, right aligdn
|`- Re: Is there a better way? [combining f-string, thousands separator, right alignStefan Ram
+- Re: Is there a better way? [combining f-string, thousands separator, right alig2QdxY4RzWzUUiLuE
`- Re: Is there a better way? [combining f-string, thousands separator, right aligdn

1
Subject: Is there a better way? [combining f-string, thousands separator, right align]
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Sun, 25 Aug 2024 15:12 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx08.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Is there a better way? [combining f-string, thousands separator,
right align]
Newsgroups: comp.lang.python
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.159 (Vovchansk; 25e128a)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 12
Message-ID: <oRHyO.142039$bV6e.134076@fx08.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 25 Aug 2024 15:12:20 GMT
X-Received-Bytes: 1021
View all headers

Subject explains it, or ask.

This is a bloody mess:

>>> s = "123456789" # arrives as str
>>> f"{f'{int(s):,}': >20}"
' 123,456,789'

--
Gilmeh

I have a rock garden. Last week three of them died. -- Richard Diran

Subject: Re: Formatting a str as a number
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Sun, 25 Aug 2024 15:42 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number
Date: 25 Aug 2024 15:42:24 GMT
Organization: Stefan Ram
Lines: 36
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <asked-20240825164104@ram.dialup.fu-berlin.de>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de udym0k88I9DbHDHnmBGKwQ632CBm/NNWL9x7mwm7gIdYJy
Cancel-Lock: sha1:f80jyYCT/63vzx8DXqp4LCziJ/k= sha256:S/ocN8IfPgn0Ohcnw7Qjlk6fDSbWYTw1GfxR1a99ZMM=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

Gilmeh Serda <gilmeh.serda@nothing.here.invalid> wrote or quoted:
>Subject explains it, or ask.

Or, you could have asked this way:

|Please fill in the implementation (replacing "pass" below) for
|the following function definition!
| |def format_number(number_str: str) -> str:
| """
| Format a string of digits as a right-aligned, comma-separated number.
| | This function takes a string of digits and returns a formatted string where:
| - The number is right-aligned in a field width of 20 characters
| - Commas are inserted as thousand separators
| - Leading spaces are added for alignment
| | Args:
| number_str (str): A string containing only digits (0-9)
| | Returns:
| str: A formatted string with the number right-aligned and comma-separated
| | Examples:
| >>> format_number("123456789")
| ' 123,456,789'
| >>> format_number("1000000")
| ' 1,000,000'
| >>> format_number("42")
| ' 42'
| >>> format_number("1234567890123456789")
| '1,234,567,890,123,456,789'
| """
| pass

Subject: Re: Formatting a str as a number
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Sun, 25 Aug 2024 15:46 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number
Date: 25 Aug 2024 15:46:25 GMT
Organization: Stefan Ram
Lines: 11
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <combination-20240825164553@ram.dialup.fu-berlin.de>
References: <oRHyO.142039$bV6e.134076@fx08.ams4> <asked-20240825164104@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 9KIg4zNYaxpdPlxKduUlswON7miPQp7qtjQeP1nMdEyEpT
Cancel-Lock: sha1:/pmSqhYWkEdPTX9B0cUQU26Q/TQ= sha256:4u+nohlodLCrD3k6P+rjh9FbqEWleOpAHUYNVqWyD9E=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>| >>> format_number("123456789")
>| ' 123,456,789'

Yeah, you totally can combine the two format specifications into one:

f"{int(number):>20,}"

.

Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
From: Pierre Fortin
Newsgroups: comp.lang.python
Date: Mon, 26 Aug 2024 01:38 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: pf@pfortin.com (Pierre Fortin)
Newsgroups: comp.lang.python
Subject: Re: Is there a better way? [combining f-string, thousands
separator, right align]
Date: Sun, 25 Aug 2024 21:38:22 -0400
Lines: 13
Message-ID: <mailman.2.1724637291.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<20240825213822.0b161c22@pfortin.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 3JuvVi513Om0zOF03o4A8AZB5XnKygb/A4GV2gTJrflQ==
Cancel-Lock: sha1:FqPz/b7/OrdG4p48Y0rF7W20j0k= sha256:RL73Q2Yda2WeCQup6iVyQxjPuDtGI6+boalY/rhg6Sw=
Return-Path: <pf@pfortin.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=pfortin.com header.i=@pfortin.com header.b=jZG6fgSj;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.041
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.02; 'aug': 0.07; 'sun,': 0.07;
'2024': 0.16; '>>>>': 0.16; 'subject:align': 0.16;
'subject:string': 0.16; 'subject:way': 0.16; 'wrote:': 0.16;
'to:addr:python-list': 0.20; 'cc:2**0': 0.25; 'it,': 0.29;
'python-list': 0.32; 'subject:there': 0.32; 'header:In-Reply-
To:1': 0.34; 'subject:]': 0.70; 'forgot': 0.84; 'subject: \n ':
0.84; 'subject:better': 0.91
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pfortin.com
; s=default;
h=Content-Transfer-Encoding:Content-Type:MIME-Version:References
:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
List-Post:List-Owner:List-Archive;
bh=MXp2g33RUU3ruPb4tmCvTdncIKsB3DJUv0HmPvYG+NA=; b=jZG6fgSj3+HO/y8o6xlLCcAOO4
cPtLG9Bh5Tb4HsWBb0dZRmq0Kw9hne2Enplv+RVvooFER/Kcclk4UnjeS5D4CcPbEiwifujZ2omtR
0Vex2e6RaF4qIAziWm21pBtqZE/nQB37Odxdmqcux5TtDgDlJ6hToDRn6Jue8S99D1xdNK6CqKGXV
D4w8BhrFbCEZ4fhAEZzC6yNz0n4vPr7fL+YUnhFzDysmqWQ9cLYb0UTX6tpgZyny/yDSws0B1yK11
WM++FD3zMVBkLogFDmReGj7kcHZHygE+f0oQYRlJ8v91mbnGfbqm1Pw5WmWSY5Ar6G2y7StNI784F
xYPeSIBQ==;
In-Reply-To: <oRHyO.142039$bV6e.134076@fx08.ams4>
X-Mailer: Claws Mail 4.3.0git9 (GTK 3.24.43; x86_64-pc-linux-gnu)
X-Get-Message-Sender-Via: ecngx348.inmotionhosting.com: authenticated_id:
pf@pfortin.com
X-Authenticated-Sender: ecngx348.inmotionhosting.com: pf@pfortin.com
X-Originating-IP: 198.46.91.127
X-SpamExperts-Domain: ecngx348.inmotionhosting.com
X-SpamExperts-Username: 198.46.91.127
Authentication-Results: servconfig.com; auth=pass
smtp.auth=198.46.91.127@ecngx348.inmotionhosting.com
X-SpamExperts-Outgoing-Class: ham
X-SpamExperts-Outgoing-Evidence: Combined (0.28)
X-Recommended-Action: accept
X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT/McEAlfriBQLPxioT4OODzPUtbdvnXkggZ
3YnVId/Y5jcf0yeVQAvfjHznO7+bT5zrZdyVoOLhYcVso5GiMJOvpCl8L9DTIFp64Frdm8ZYl7zL
E8/wV9b3b81AyPIwTZPxXi0858vbo/S2v6neZJk6s8vzOhLGfuNMwru2XoJU6uWta+K53aFc8m9Z
bXP1L3Vl8dmsxDwp7RnymMoVR6CJDay26Uht2YE0QPb0g8Vb+x3CTXTiJAERzvNeJKL1HJ3XWAZ5
W+UFmJmuew/D9ljpZsgLuXmBcoVAwtlOsmDRCaKd6Xeqm3xLXztxB4Lk5FFQHTHnHCfQlWiHz6cy
iF60AdeXjCDBOomVNP9963OKUwZXTaHOP7oKW7n27myvseKRqlQE9b1hXhIRJ1bJW0V1UYfuzJ1m
8O31zlHQ8Dw4NmzfO6ib3rryOBZGk86Mee0fTjrYxVWetnNJmJU0xg+46+MR9Nol7RZuMNLAjhWw
OH8CTlQwpHklpufi6pZ4ylW5njSUhBnTQRr7XDNUKDlrDzn23lmbQ455+TwtsPDDuZi5IvY2WxpX
FqNriEKWAI+rEPGaUfvTQD8mTYnm5Vyb/eB36XvbBuC1U1srT4VxcBqZR3KVQgqF/fPYYAfEfsjN
MenojtnS5GFKIk+a4YL3GESgodMh3S0GT0bXwYcbwl5mQMlC2RMoPaOM1YJMY2b+6INYTgBX/7uM
ttOrQ9pKeWcAcvt5SsFrbwQ6VPBItKbAvktuOzccmiJIz3CLNOD3Y80OmAux3oN13+ztUzneXMXK
jaxv10oXApQLRVegYgSIGxzBF2u2H7X6hZMNOOxxfpYDjGTZ0x3acMshIoiRTGxbWpJg4KvmdOet
HkukFYjKFojrvUjjKLsywQkk4eqj6DjaSkcyk3JPaZt9ZSFcbmNSPeYOYiS9l8d+2BjaTA7S8/qi
rGjH0urkD3BNNHahg6Ya+z7k1o8hIqau5lMycqTM6cyT/IU1TY5PvweZ+izS555JC/eJE0J20PW7
DICs9uj8bOqE9zVJwqYsk3or2rrLp4UyH4Wq0vyDWCqziKxpKsL8zANCAlYA5EIMyDalD8hMDE+I
WRKY4dAE1QFbCF6OGZGmgP1HDx13ZatXAA==
X-Report-Abuse-To: spam@se1-lax1.servconfig.com
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20240825213822.0b161c22@pfortin.com>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
View all headers

On Sun, 25 Aug 2024 15:12:20 GMT Gilmeh Serda via Python-list wrote:

>Subject explains it, or ask.
>
>This is a bloody mess:
>
>>>> s = "123456789" # arrives as str
>>>> f"{f'{int(s):,}': >20}"
>' 123,456,789'
>
Oops.. forgot comma

f"{int(s):>20,}"

Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
From: MRAB
Newsgroups: comp.lang.python
Date: Mon, 26 Aug 2024 01:55 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Is there a better way? [combining f-string, thousands separator,
right align]
Date: Mon, 26 Aug 2024 02:55:03 +0100
Lines: 20
Message-ID: <mailman.3.1724637492.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<85ea3168-cd47-4f06-97f8-5f98ee21c8b9@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 00gIRkO2WttKrZEyzynsVw2fWm8DjfWO3uW0m9AAX5vg==
Cancel-Lock: sha1:DMI2PNSs+tHtNKCaLYahFkoI2Kc= sha256:4HpM91BIA3Uvh6tiBj/jgzjTny2KVclFiiRrwwC83gw=
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=lvJ+oNUs;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'from:addr:python': 0.09;
'received:192.168.1.64': 0.09; 'subject:, \n ': 0.09; '>>>>':
0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab':
0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:plus.net': 0.16; 'subject:align': 0.16;
'subject:string': 0.16; 'subject:way': 0.16; 'wrote:': 0.16;
'to:addr:python-list': 0.20; '>>>': 0.28; 'it,': 0.29; 'header
:User-Agent:1': 0.30; 'default': 0.31; 'python-list': 0.32;
'subject:there': 0.32; 'received:192.168.1': 0.32; 'header:In-
Reply-To:1': 0.34; 'received:192.168': 0.37; 'format': 0.62;
'received:212': 0.62; 'subject': 0.63; 'subject:]': 0.70;
'subject:better': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1724637304; bh=Qs5M6sX+Irh9p59bFnGgDLrWVxawPM2pXhpdfo7e3KQ=;
h=Date:Subject:To:References:From:In-Reply-To;
b=lvJ+oNUso0NtB0MXhOirZOA66bexqLmk8Jvyfbd7iiNvt9Mi/tPObqL3zKz6h9p0l
s1murCLb3qRQZbBnt283WC24kDXw/RL4L1/UhA8wbO2VWwjVncIxBG02uWYMv7umhT
+d6zA06yPD9q8KCsQGtTV1jcvK1iUuwXs7en4SmTBC1t6cPgIotQHCY5c7lbpnKRqF
5MhhSdGgmgAyRPFY82omJip6NHFMBRcIRue1MKZsV+aHYxyGSpRB1Ar1e9cfEOG9o7
2Iu9rivthdm+xkWpqMZarEpudTwpKDbuth34g1gZruanpRnVS1U/aBAP/Ffyc4LG54
dpmi4scRh4tfw==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=VaJUP0p9 c=1 sm=1 tr=0 ts=66cbe078
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=MV0liI4DTSMKKfbT:21 a=IkcTkHD0fZMA:10 a=7YnVGVZCoM_dpXUQtdsA:9
a=QEXdDO2ut3YA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <oRHyO.142039$bV6e.134076@fx08.ams4>
X-CMAE-Envelope: MS4xfBmfVg0KKEOJ4S1d8oyyGU/QHkUR/gAwiOdgyN1i492MBvTF1f+hrj29YOMKaXC1kINaf8OMx4f1H/OuBI0rKHkcjkx8kJw6A7f0egBbYGYfHXnVlq9p
iuG9A5YgNiFMPYK2kOv8EPZu5U2phVtK1qrD5YrjgJ2d4UZhXAmCTJaNuRBVBHKR2oeV2OlWJ0U+tZmR0TEpE6oeuj1bq5gpJlQ=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <85ea3168-cd47-4f06-97f8-5f98ee21c8b9@mrabarnett.plus.com>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
View all headers

On 2024-08-25 16:12, Gilmeh Serda via Python-list wrote:
> Subject explains it, or ask.
>
> This is a bloody mess:
>
>>>> s = "123456789" # arrives as str
>>>> f"{f'{int(s):,}': >20}"
> ' 123,456,789'
>
You don't need to format twice; you can combine them:

>>> s = "123456789"
>>> f'{int(s): >20,}'
' 123,456,789'

or if you rely on default behaviour:

>>> f'{int(s):20,}'
' 123,456,789'

Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
From: Pierre Fortin
Newsgroups: comp.lang.python
Date: Mon, 26 Aug 2024 01:34 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: pf@pfortin.com (Pierre Fortin)
Newsgroups: comp.lang.python
Subject: Re: Is there a better way? [combining f-string, thousands
separator, right align]
Date: Sun, 25 Aug 2024 21:34:51 -0400
Lines: 12
Message-ID: <mailman.6.1724640924.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<20240825213451.7f786f57@pfortin.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de ojImxFhBFn3f0f+07eJEjg0LnLOL3tlZhzH3nln/RBiA==
Cancel-Lock: sha1:Shx3qZccpPdUSmfIRsmG9lUT6L0= sha256:RHNwW853MNAiWJ4hw5sPP5xbsS5P3ACzl7nglXfm7ww=
Return-Path: <pf@pfortin.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=pfortin.com header.i=@pfortin.com header.b=FaCvE24H;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.034
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.01; 'aug': 0.07; 'sun,': 0.07;
'2024': 0.16; '>>>>': 0.16; 'subject:align': 0.16;
'subject:string': 0.16; 'subject:way': 0.16; 'wrote:': 0.16;
'to:addr:python-list': 0.20; 'cc:2**0': 0.25; 'it,': 0.29;
'python-list': 0.32; 'subject:there': 0.32; 'header:In-Reply-
To:1': 0.34; 'received:199': 0.69; 'subject:]': 0.70; 'subject: \n
': 0.84; 'subject:better': 0.91
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pfortin.com
; s=default;
h=Content-Transfer-Encoding:Content-Type:MIME-Version:References
:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:
List-Post:List-Owner:List-Archive;
bh=Cubqng89A0rukAibmpIaPhR7YLSwNIWPlucownMmblg=; b=FaCvE24HvhC2PoahKmtqxYCvr7
h/QBGgreT4Uz3gcUj8QI2Uq5d9BX5D+zIRrD2wLuUpHHNLbYgDv8mP1ApnWu99kY8nqzmE77jheDb
v1CX9XwB2MIzT+4Zh7RAVvnmoEsSflzxOjMPGi07XHUzfaYvOO3zB2OzyPQp/UhRL5oMe1qIrIxNt
YsYkopzPK7NjFs2dCZdx2icBnq5mxv1EcdJYG7uC8XFN6ZSVwgjf23CHsQbv9J/ye8GVBqLsN8zz+
U/OVAaQmb8Dj7UqV4+BILeo0kpo2ZQP27E2117Bz/UwoCEvZTBKHqBxelzcMdtZKg152DrOSlssmH
B/LmrlDw==;
In-Reply-To: <oRHyO.142039$bV6e.134076@fx08.ams4>
X-Mailer: Claws Mail 4.3.0git9 (GTK 3.24.43; x86_64-pc-linux-gnu)
X-Get-Message-Sender-Via: ecngx348.inmotionhosting.com: authenticated_id:
pf@pfortin.com
X-Authenticated-Sender: ecngx348.inmotionhosting.com: pf@pfortin.com
X-Originating-IP: 198.46.91.127
X-SpamExperts-Domain: ecngx348.inmotionhosting.com
X-SpamExperts-Username: 198.46.91.127
Authentication-Results: servconfig.com; auth=pass
smtp.auth=198.46.91.127@ecngx348.inmotionhosting.com
X-SpamExperts-Outgoing-Class: ham
X-SpamExperts-Outgoing-Evidence: Combined (0.24)
X-Recommended-Action: accept
X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT+aNZhU4Tqmh6RPAhJzQtN4PUtbdvnXkggZ
3YnVId/Y5jcf0yeVQAvfjHznO7+bT5zrZdyVoOLhYcVso5GiMJOvpCl8L9DTIFp64Frdm8ZYl7zL
E8/wV9b3b81AyPIwTZPxXi0858vbo/S2v6neZJk6s8vzOhLGfuNMwru2XoJU6mIwuwJXJGpifhN1
th0saPRl8dmsxDwp7RnymMoVR6CJDay26Uht2YE0QPb0g8Vb+x3CTXTiJAERzvNeJKL1HJ3XWAZ5
W+UFmJmuew/D9ljpZsgLuXmBcoVAwtlOsmDRCVT2sdrgtBZkkjKrLziq8N4F1vLM9cIybVokPLVw
NGeGAdeXjCDBOomVNP9963OKUwZXTaHOP7oKW7n27myvseKRqlQE9b1hXhIRJ1bJW0V1UYfuzJ1m
8O31zlHQ8Dw4NmzfO6ib3rryOBZGk86Mee0fTjrYxVWetnNJmJU0xg+46+MR9Nol7RZuMNLAjhWw
OH8CTlQwpHklpufi6pZ4ylW5njSUhBnTQRr7XDNUKDlrDzn23lmbQ455+TwtsPDDuZi5IvY2WxpX
FqNriEKWAI+rEPGaUfvTQD8mTYnm5Vyb/eB36XvbBuC1U1srT4VxcBqZR3KVQgqF/fPYYAfEfsjl
BVGlg2HG1V5/WOPTwz68Tk9CgYUIkxClejfBHaGDSbr9mngkA413vVRycyr76ynl806eCKWk31Oy
liaXTykYlRK80x3csr6hp1YWIAAxMCPNOLiRQUgGOloFElbZLF4RFZ4oobg8BBg3Jq+ntzj0hVi6
aQRMfQurcz45purm0ZyLwkuKI51yRR7AImuZBFykBJTycjSXYBbCRRLP/dzFDaootgac9AU/HSoj
RIrGceQJyPsBMRItmV2XMBZo/xu03pDqi/PJRa1H+KrDbFh2XRs+tu+0MI3KZT7cpJSeDnCxQEQl
+7yMYcPNbrwQiotWBpRKR65hsiHI9Nuxn7ymXMiTx/S2ki6+9c/8Qxcnr5bMIguYt7wybfRQGlg3
ILxoMMMh30z0ou3Uma6ICBqo8eNyupB7Ak0eQEQVLmVl4uOGY/fU/ez09WfodcRb6XIeBSpfGnwj
CEXYE5OgK4yvokvlqzub5SyHO8sLBcuZsQ==
X-Report-Abuse-To: spam@se1-lax1.servconfig.com
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <20240825213451.7f786f57@pfortin.com>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
View all headers

On Sun, 25 Aug 2024 15:12:20 GMT Gilmeh Serda via Python-list wrote:

>Subject explains it, or ask.
>
>This is a bloody mess:
>
>>>> s = "123456789" # arrives as str
>>>> f"{f'{int(s):,}': >20}"
>' 123,456,789'
>

f"{s:>20}"

Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
From: dn
Newsgroups: comp.lang.python
Organization: DWM
Date: Mon, 26 Aug 2024 08:42 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Is there a better way? [combining f-string, thousands separator,
right align]
Date: Mon, 26 Aug 2024 20:42:32 +1200
Organization: DWM
Lines: 53
Message-ID: <mailman.8.1724661765.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<09102d57-41cd-4428-b96f-d69e2ffe9c95@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de liRU+UsTQJDI5fHU4HUkLQp1Vh9GsgHlMkeRfqGkMtXg==
Cancel-Lock: sha1:CH5cfXM74ZLSpWf94AobkPPpa1k= sha256:YIg6dh6buYHp4KCClPZt31lWOe9NWxv+skw85FL32Oo=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=PJTVBSBV; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.068
X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'string': 0.07; '=dn':
0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'subject:, \n ': 0.09; '>>>>': 0.16;
'css': 0.16; 'expressions': 0.16; 'indeed': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'subject:align': 0.16;
'subject:string': 0.16; 'subject:way': 0.16; 'wrote:': 0.16;
'to:addr:python-list': 0.20; 'do,': 0.26; '>>>': 0.28; 'settings':
0.28; 'it,': 0.29; 'header:User-Agent:1': 0.30; 'default': 0.31;
'header:Organization:1': 0.31; 'ease': 0.32; 'python-list': 0.32;
'subject:there': 0.32; 'received:192.168.1': 0.32; 'header:In-
Reply-To:1': 0.34; 'presented': 0.37; "skip:' 10": 0.37; 'really':
0.37; 'received:192.168': 0.37; 'could': 0.38; 'added': 0.39;
'define': 0.40; 'both': 0.40; 'want': 0.40; 'should': 0.40;
'higher': 0.60; 'format': 0.62; 'subject': 0.63; 'ever': 0.63;
'thus': 0.64; 'your': 0.64; 'matter': 0.68; 'further': 0.69;
'obvious': 0.69; 'within': 0.69; 'subject:]': 0.70; 'skip:f 30':
0.71; 'skip:f 20': 0.75; 'html': 0.80; 'states': 0.80; 'further,':
0.84; 'subject:better': 0.91
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud C50C56844
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1724661758;
bh=59vOgzeQKyopLDGSvbbA97ul7OUQ9s4daPAhx8zY92U=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=PJTVBSBVdEReMjd2tTnLZvRGQD8ge3e+ILR9c9YdT1gi5OTuW3CnXvro+qAB1n+7C
mf4M9Ii+H0uv8IB/IzD0OY3ygb5A+62O27pcy/S0Bi7vd8g19pmzca0pzFxFgdOVik
OoIkNuXG3JN26C6ZBKzyUmimm/GDcTLbzn8K0KCnUdCKL6NoCDB2/4JyN/GYEgFz6P
DDPzyLJu+dyGxmGUsTr9veoBolZn7MijTW6HVx44xj8SiIS0zwmpDeQVzsqMpnOpsE
j7EeoIU/7BDGXhzq5MBG60gEXtA62C8CYvEtsq118SEy+SjyqsbM5se1ffGuAvSvXz
Qze0axJ+iypsA==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <oRHyO.142039$bV6e.134076@fx08.ams4>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <09102d57-41cd-4428-b96f-d69e2ffe9c95@DancesWithMice.info>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
View all headers

On 26/08/24 03:12, Gilmeh Serda via Python-list wrote:
> Subject explains it, or ask.
>
> This is a bloody mess:
>
>>>> s = "123456789" # arrives as str
>>>> f"{f'{int(s):,}': >20}"
> ' 123,456,789'

With recent improvements to the expressions within F-strings, we can
separate the string from the format required. (reminiscent of FORTRAN
which had both WRITE and FORMAT statements, or for that matter HTML
which states the 'what' and CSS the 'how')

Given that the int() instance-creation has a higher likelihood of
data-error, it is recommended that it be a separate operation for ease
of fault-finding - indeed some will want to wrap it with try...except.

>>> 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}}"
' 123,456,789'

Further, some of us don't like 'magic-constants', hence (previously):

>>> S_FIELD_WIDTH = 20
>>> s_format = F">{S_FIELD_WIDTH},"

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!

--
Regards,
=dn

Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Date: Mon, 26 Aug 2024 11:00 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4RzWzUUiLuE@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Is there a better way? [combining f-string, thousands separator,
right align]
Date: Mon, 26 Aug 2024 06:00:32 -0500
Lines: 30
Message-ID: <mailman.9.1724670045.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<09102d57-41cd-4428-b96f-d69e2ffe9c95@DancesWithMice.info>
<ZsxgUBEdOsVL6c49@anomaly>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de ACO/mNt40EELhHvREHp+PQ0sHLx/sFyaHptNUW3jS8wg==
Cancel-Lock: sha1:TICZOzzz088gv124ZICCUaOEsKc= sha256:MF5tPg+ej0FdRDaygluWT85KXEuFO3EoSVA0vOTIiM4=
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=potatochowder.com header.i=@potatochowder.com
header.b=C43jfDgw; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.020
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '(for': 0.05; ';-)': 0.07;
'users,': 0.07; 'received:78': 0.09; 'subject:, \n ': 0.09;
'from:addr:2qdxy4rzwzuuilue': 0.16; 'from:addr:potatochowder.com':
0.16; 'okay,': 0.16; 'parsing': 0.16; 'received:136.243': 0.16;
'received:78.46': 0.16; 'received:78.46.172': 0.16;
'received:www458.your-server.de': 0.16; 'received:your-server.de':
0.16; 'rpg': 0.16; 'subject:align': 0.16; 'subject:string': 0.16;
'subject:way': 0.16; 'wrote:': 0.16; "can't": 0.17; "aren't":
0.19; 'to:addr:python-list': 0.20; 'code': 0.23; 'url:wiki': 0.23;
'received:de': 0.23; 'actual': 0.25; 'do,': 0.26; "isn't": 0.27;
'>>>': 0.28; 'settings': 0.28; 'default': 0.31; 'python-list':
0.32; 'received:136': 0.32; 'said,': 0.32; 'subject:there': 0.32;
"i'll": 0.33; 'header:In-Reply-To:1': 0.34; 'files': 0.36;
'really': 0.37; 'file': 0.38; 'could': 0.38; 'added': 0.39;
'still': 0.40; 'want': 0.40; 'ever': 0.63; 'thus': 0.64; 'your':
0.64; 'back': 0.67; 'further': 0.69; 'subject:]': 0.70; 'url-
ip:208.80.154/24': 0.70; 'url-ip:208.80/16': 0.70;
'url:wikipedia': 0.70; 'skip:f 30': 0.71; 'url-ip:208/8': 0.71;
'global': 0.73; "you'll": 0.73; 'apparent': 0.84; 'caused': 0.86;
'subject:better': 0.91; 'hole': 0.93
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=potatochowder.com; s=default2305; h=In-Reply-To:Content-Transfer-Encoding:
Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date:Sender:
Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:
Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=acL4G3x1LLYGFq/rYgYxJUcWGcivgcD2HwT2VNu1vfQ=; b=C43jfDgwCWdXaF0TrS9ivdyphT
n57J+04DztrHn0TfBfFOdS07bZMTd5G7U80LLJo24tq2FY6FadXGuWgtWl6h6Ogd7LcLpfcCRaJlV
4POpugoTBjf6AXIf2ngwj5BP1jmhwiDvnvibHcD8WSjP/vSsBmk1DOL7E3MBLRmfpu5ePK5eEF755
duWLPDZo0mH4hPuOmbfwcE0R9OZZWwHX9yJX9TJRhsVi6gt4311UWNRgWuFpjDFC5E3poi4RBuTBn
dllXMY8LoD0CWg+q862LesXqNqVw6Ah8R8SVL4ncOvNo2busSukt0osbZCw86aPicV3JVp3Y/oJT9
yvShXLVQ==;
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <09102d57-41cd-4428-b96f-d69e2ffe9c95@DancesWithMice.info>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.10/27379/Mon Aug 26 10:48:32 2024)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <ZsxgUBEdOsVL6c49@anomaly>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<09102d57-41cd-4428-b96f-d69e2ffe9c95@DancesWithMice.info>
View all headers

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.

Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Mon, 26 Aug 2024 11:30 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
Date: 26 Aug 2024 11:30:44 GMT
Organization: Stefan Ram
Lines: 20
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <CALL-20240826122738@ram.dialup.fu-berlin.de>
References: <oRHyO.142039$bV6e.134076@fx08.ams4> <mailman.8.1724661765.2917.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de OMLPdn2bRo/wSVEX8ULDzA6C+UglIZooPjRAk51FdYsFa7
Cancel-Lock: sha1:TXpWUke9NmT8rTL/jy0v5+kNVWQ= sha256:ddD6iDMrquF9e4gWbAm5rdMuGMGX9+ZuN/vkjY6A+/4=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

dn <PythonList@DancesWithMice.info> wrote or quoted:
>and if we really want to go over-board:
> >>>RIGHT_JUSTIFIED = ">"
> >>>THOUSANDS_SEPARATOR = ","
> >>>s_format = F"{RIGHT_JUSTIFIED}{S_FIELD_WIDTH}{THOUSANDS_SEPARATOR}"

def PROCEDURE_DEFINIION( NAME, BODY ):
return f'\ndef {NAME}():\n{" "*4}{BODY}\n'

def PRINT_STATEMENT( WHAT_TO_PRINT ):
return f'print( "{WHAT_TO_PRINT}" )'

def PROCEDURE_INVOCATION( WHAT_TO_INVOKE ):
return f'{WHAT_TO_INVOKE}()'

exec\
( PROCEDURE_DEFINIION( "f", PRINT_STATEMENT( "Hello, world!" ))+
PROCEDURE_INVOCATION( "f" ))

Subject: Re: Is there a better way? [combining f-string, thousands separator, right align]
From: dn
Newsgroups: comp.lang.python
Organization: DWM
Date: Mon, 26 Aug 2024 20:27 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Is there a better way? [combining f-string, thousands separator,
right align]
Date: Tue, 27 Aug 2024 08:27:11 +1200
Organization: DWM
Lines: 108
Message-ID: <mailman.10.1724704040.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<09102d57-41cd-4428-b96f-d69e2ffe9c95@DancesWithMice.info>
<ZsxgUBEdOsVL6c49@anomaly>
<96f83373-c7ad-4020-96b0-51d956cf433d@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de f+KGKLQe8tG17VLShC1PSA8dCY160llShaZoKSnbfLPQ==
Cancel-Lock: sha1:cdfwWylqZVsQTwSqxBnaUO4ZE8c= sha256:9TY8qCkh7y2KBO8c37PQ5EsL0U2APy9DnnBGzwAh2lE=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=qL7koi1b; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.026
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '(for': 0.05;
'improvement': 0.05; ';-)': 0.07; 'correct?': 0.07; 'users,':
0.07; '=dn': 0.09; 'admins': 0.09; 'consistency': 0.09; 'dan':
0.09; 'environments': 0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'json': 0.09; 'linux': 0.09;
'options,': 0.09; 'received:192.168.1.64': 0.09; 'subject:, \n ':
0.09; "they've": 0.09; '(without': 0.16; '.py': 0.16; '>>>>>':
0.16; 'command-line': 0.16; 'compromise.': 0.16; 'explaining':
0.16; 'form:': 0.16; 'limitations.': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'okay,': 0.16; 'parsing': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'rpg': 0.16;
'setuptools': 0.16; 'spot': 0.16; 'subject:align': 0.16;
'subject:string': 0.16; 'subject:way': 0.16; 'values,': 0.16;
'wrote:': 0.16; "can't": 0.17; "aren't": 0.19; 'libraries': 0.19;
'to:addr:python-list': 0.20; "i've": 0.22; 'code': 0.23;
'installed': 0.23; 'url:wiki': 0.23; 'run': 0.23; '(and': 0.25;
'actual': 0.25; 'anyone': 0.25; 'do,': 0.26; 'programming,': 0.26;
"isn't": 0.27; 'else': 0.27; 'old': 0.27; 'settings': 0.28; 'it,':
0.29; 'header:User-Agent:1': 0.30; 'whole': 0.30; 'attempt': 0.31;
'takes': 0.31; 'default': 0.31; 'putting': 0.31;
'header:Organization:1': 0.31; '(as': 0.32; 'files,': 0.32;
'python-list': 0.32; 'said,': 0.32; 'subject:there': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; "i'll": 0.33; 'there':
0.33; 'windows': 0.34; 'package': 0.34; 'header:In-Reply-To:1':
0.34; 'majority': 0.35; 'usual': 0.35; 'files': 0.36; 'fix': 0.36;
'errors': 0.36; 'those': 0.36; 'really': 0.37; 'using': 0.37;
'received:192.168': 0.37; 'file': 0.38; 'could': 0.38; 'changes':
0.39; 'added': 0.39; 'valid': 0.39; 'methods': 0.39; 'still':
0.40; 'files.': 0.40; 'want': 0.40; 'try': 0.40; 'including':
0.60; 'skip:h 10': 0.61; 'format': 0.62; 'point.': 0.62; 'skip:z
10': 0.62; 'here': 0.62; 'ever': 0.63; 'updates': 0.64; 'full':
0.64; 'thus': 0.64; 'your': 0.64; 'well': 0.65; 'back': 0.67;
'decision': 0.68; 'further': 0.69; 'azure': 0.69; 'boss': 0.69;
'establishing': 0.69; 'took': 0.69; 'older': 0.70; 'subject:]':
0.70; 'url-ip:208.80.154/24': 0.70; 'url-ip:208.80/16': 0.70;
'url:wikipedia': 0.70; 'skip:f 30': 0.71; 'url-ip:208/8': 0.71;
'longer': 0.71; 'global': 0.73; "you'll": 0.73; 'manage': 0.73;
'costs': 0.74; 'easy': 0.74; '....': 0.76; 'clients.': 0.76;
'proven': 0.76; 'moment': 0.81; 'adjusting': 0.84; 'apparent':
0.84; 'realise': 0.84; 'say,': 0.84; 'thus,': 0.84; 'veritable':
0.84; 'written,': 0.84; 'caused': 0.86; 'service,': 0.91;
'subject:better': 0.91; "world's": 0.91; 'hole': 0.93; 'humanity':
0.93; 'pressed': 0.93; 'skip:q 20': 0.95
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 079FF68A5
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1724704037;
bh=Ojf7v2wgM3XPmO9+En6gykW6U2NoYwwHOBrJFIuQKuU=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=qL7koi1bf2Se0Rzb+Yjt7DTeECM/DjZgPZDlJlXaPIXmh7YOBfnjy1uaq4dGjCB/6
kU5iQpuukqPzZm3ND+tzOHTyrRtsLOZdHtqT1TFjMcDXwqa7HDd74tT8oC4JXD2Vpx
CvUe1qEqwKW34sXSLRO0kzTdIzF4pZ5JiK1Cup5SCT6cH1KAoX0aT7ZsD/3i+3S431
ZEHoSb0hCt+aqLpMmTi77go6DMYEfDTz55MiLCTbzn/eR/SZlQo0xycvY0dsHb0GmW
hcOlNhFl4XzhdX0NobpchximJiTtUXg8C+5OPICDjl5iwQTocev1+sDTg+Vv3US26k
qJflrztntiRLw==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <ZsxgUBEdOsVL6c49@anomaly>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <96f83373-c7ad-4020-96b0-51d956cf433d@DancesWithMice.info>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<09102d57-41cd-4428-b96f-d69e2ffe9c95@DancesWithMice.info>
<ZsxgUBEdOsVL6c49@anomaly>
View all headers

On 26/08/24 23:00, Dan Sommers via Python-list wrote:
> 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.

Not at all. Please continue to question/ask/suggest!

This is a valid point. There are costs and benefits (trade-offs) to all
decisions!

That said, writing one's own parser would become a veritable can of
worms/rabbit hole. Here be dragons!

Similarly, explaining this takes longer than writing the example itself!

Older Windows users will know about .ini files, and Linux Admins are
familiar with .conf files. Many of us are already using JSON or YAML
formats. Any of these (and more) could be pressed into service, as
above. At the 'top end', there are also whole libraries devoted to
establishing application configuration or "environments": default
values, config files, command-line options, user-input...

Have switched to using Python-poetry, which replaces packaging methods
such as setuptools (as well as virtual-environment tools). It takes its
project configuration specifications from a pyproject.toml file. So, for
a few projects lately, I've been using .toml for application-config as
well. However, I have to say, this more from an attempt at consistency
than a decision of logic. (critique welcome)

That said, a setup.py configuration, took the form:

setup(
name='demo_project',
version='1.1.0',
packages=find_packages(),
install_requires=[
'requests',
'numpy',
...
],
entry_points={
....

Accordingly, it offers an example of the simplest format (for us), and
one which has a zero-learning pre-requisite. At execution-time, the
moment such a config is import-ed, a syntax-error will immediately bring
proceedings to a halt!

I have some stats-wonks as clients. They dabble in programming, but
(fortunately) realise their limitations. (usually!) The boss has had to
ban them from 'improving' my code ($paid to be an improvement on their
usual quality), but including a .py configuration/options file has
proven to be an honor-preserving compromise. Of course, they manage
their own runs, adjusting parameters as they go. So, any errors are
their own, and they can fix themselves (without anyone else knowing!).

Such would not work in many?most other environments - children: do not
try this at home!

An irritation for those of us who have to delve into projects after
they've been written, is a git-history full of the sorts of
user-tweaking changes vilified earlier. Putting user-config into a
separate file, even a separate sub-directory, makes it easy to spot
which updates to ignore, and thus, which to consider!

PS the reason why CrowdStrike was not the end of humanity as we know it,
(and only that of those who only know MSFT's eco-system) is because the
majority of the world's Internet servers run Linux - including Azure
(brings to mind the old saw: the package said "runs on Windows-95 or
better" so I installed it on Linux!)

Joking aside, we (virtuous ones) ALWAYS test BEFORE release. Correct?

--
Regards,
=dn

Subject: Re: Formatting a str as a number
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Tue, 27 Aug 2024 20:48 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx09.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Re: Formatting a str as a number
Newsgroups: comp.lang.python
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.159 (Vovchansk; 25e128a)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 13
Message-ID: <vYqzO.8$fip4.7@fx09.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Tue, 27 Aug 2024 20:48:27 GMT
X-Received-Bytes: 1183
View all headers

On 25 Aug 2024 15:46:25 GMT, Stefan Ram wrote:

> f"{int(number):>20,}"

Great. Thanks. Do you have a link to where that's documented?

I did web search, found nothing.

--
Gilmeh

When a fellow says, "It ain't the money but the principle of the thing,"
it's the money. -- Kim Hubbard

Subject: Re: Formatting a str as a number
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Tue, 27 Aug 2024 21:36 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number
Date: 27 Aug 2024 21:36:47 GMT
Organization: Stefan Ram
Lines: 24
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <doc-20240827223515@ram.dialup.fu-berlin.de>
References: <oRHyO.142039$bV6e.134076@fx08.ams4> <asked-20240825164104@ram.dialup.fu-berlin.de> <combination-20240825164553@ram.dialup.fu-berlin.de> <vYqzO.8$fip4.7@fx09.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de YrYn2l/6mADrw7QqYjXn7Az9S299OJD1vtAzoqdewAphhR
Cancel-Lock: sha1:GG7julEZlAcMiaVyBbyFhXw5JFI= sha256:mbrRlynJY9odK4uv3l9ZODc3TMJrAj+EirzfS3VxZ/o=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

Gilmeh Serda <gilmeh.serda@nothing.here.invalid> wrote or quoted:
>On 25 Aug 2024 15:46:25 GMT, Stefan Ram wrote:
>>f"{int(number):>20,}"
>Great. Thanks. Do you have a link to where that's documented?
>I did web search, found nothing.

Stoked to hear you're into it!

For docs, I usually snag the PDFs from "python.org," especially
"reference.pdf" (the Python Language Reference) and "library.pdf"
(the Python Library Reference), then I search them for keywords.

The f-string stuff is laid out in "The Python Language Reference"
since they're part of the language itself. A quick search for
"f-str" gets you to "2.4.3 Formatted string literals," which says,
"The result is then formatted using the format() protocol." So, you
got to check out "The Python Library Reference" too! Searching for
"format(" there zooms you right to "6.1.3 Format String Syntax"
(via "Format Specification Mini-Language").

But honestly, I usually just hit up a chatbot first. I'll drop
in my code and say, "How can I make this shorter?".

Subject: Re: Formatting a str as a number
From: Grant Edwards
Newsgroups: comp.lang.python
Date: Tue, 27 Aug 2024 21:39 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: grant.b.edwards@gmail.com (Grant Edwards)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number
Date: Tue, 27 Aug 2024 17:39:21 -0400 (EDT)
Lines: 12
Message-ID: <mailman.12.1724794762.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
X-Trace: news.uni-berlin.de MSJJZwFqTcGepRkzFKtw4g6A9x785h5Sk3RzBUlRsSWw==
Cancel-Lock: sha1:SBpJ348DCwDj8nS4mjuCramavLw= sha256:2+cXmgtGHRMnGL8mCyLifbqLKhKun9o3jDDTc3DE0sg=
Return-Path: <grant.b.edwards@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'aug': 0.07; 'ram': 0.07;
'search,': 0.09; 'url:reference': 0.09; '2024': 0.16;
'from:addr:grant.b.edwards': 0.16; 'from:name:grant edwards':
0.16; 'great.': 0.16; 'nothing.': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.20; 'stefan': 0.26; 'header:User-Agent:1': 0.30;
'python-list': 0.32; 'from:addr:gmail.com': 0.35; 'message-
id:invalid': 0.68; 'skip:f 20': 0.75
User-Agent: slrn/1.0.3 (Linux)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <4Wtgt14jXFznWHr@mail.python.org>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4>
View all headers

On 2024-08-27, Gilmeh Serda via Python-list <python-list@python.org> wrote:
> On 25 Aug 2024 15:46:25 GMT, Stefan Ram wrote:
>
>> f"{int(number):>20,}"
>
> Great. Thanks. Do you have a link to where that's documented?
>
> I did web search, found nothing.

https://docs.python.org/3/library/string.html#formatspec
https://docs.python.org/3/reference/lexical_analysis.html#f-strings

Subject: Re: Formatting a str as a number
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Fri, 30 Aug 2024 05:22 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.bawue.net!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx01.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Re: Formatting a str as a number
Newsgroups: comp.lang.python
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.160 (Toresk; 9d04e24)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 20
Message-ID: <dGcAO.20275$Ic_6.799@fx01.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Fri, 30 Aug 2024 05:22:17 GMT
X-Received-Bytes: 1591
View all headers

On Tue, 27 Aug 2024 17:39:21 -0400 (EDT), Grant Edwards wrote:

> On 2024-08-27, Gilmeh Serda via Python-list <python-list@python.org> wrote:
>> On 25 Aug 2024 15:46:25 GMT, Stefan Ram wrote:
>>
>>> f"{int(number):>20,}"
>>
>> Great. Thanks. Do you have a link to where that's documented?
>>
>> I did web search, found nothing.
>
> https://docs.python.org/3/library/string.html#formatspec
> https://docs.python.org/3/reference/lexical_analysis.html#f-strings

Thanks. I'll check those as time allows.

--
Gilmeh

National security is in your hands - guard it well.

Subject: Re: Formatting a str as a number
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Fri, 30 Aug 2024 05:25 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.mixmin.net!news.neodome.net!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx01.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Re: Formatting a str as a number
Newsgroups: comp.lang.python
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <doc-20240827223515@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.160 (Toresk; 9d04e24)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 23
Message-ID: <oJcAO.20276$Ic_6.3999@fx01.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Fri, 30 Aug 2024 05:25:40 GMT
X-Received-Bytes: 1748
View all headers

On 27 Aug 2024 21:36:47 GMT, Stefan Ram wrote:

> For docs, I usually snag the PDFs from "python.org," especially
> "reference.pdf" (the Python Language Reference) and "library.pdf"
> (the Python Library Reference), then I search them for keywords.

Thanks, that's a good idea. I've usually gone for the web docs only.

> The f-string stuff is laid out in "The Python Language Reference"
> since they're part of the language itself. A quick search for
[snip]

Great. Thanks. I'll try to remember that.

> But honestly, I usually just hit up a chatbot first. I'll drop
> in my code and say, "How can I make this shorter?".

In other words, a shortcut. :)

--
Gilmeh

More people are flattered into virtue than bullied out of vice. -- R. S. Surtees

Subject: Re: Formatting a str as a number - Okay, one more related thing...
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Sat, 31 Aug 2024 05:31 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!newsfeed.bofh.team!2.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!193.141.40.65.MISMATCH!npeer.as286.net!npeer-ng0.as286.net!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx06.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Re: Formatting a str as a number - Okay, one more related thing...
Newsgroups: comp.lang.python
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
<dGcAO.20275$Ic_6.799@fx01.ams4>
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.160 (Toresk; 9d04e24)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 21
Message-ID: <tUxAO.85679$fD72.80638@fx06.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sat, 31 Aug 2024 05:31:05 GMT
X-Received-Bytes: 1538
View all headers

On Fri, 30 Aug 2024 05:22:17 GMT, Gilmeh Serda wrote:

> f"{int(number):>20,}"

I can find "," (comma) and I can find "_" (underscore) but how about " "
(space)?

Or any other character, for that matter?

Any ideas?

Of course I can do f"{123456:>20_}".replace("_", " "), just thought there
might be something else my search mojo fails on.

Thanks.

--
Gilmeh

Diplomacy is to do and say, the nastiest thing in the nicest way. --
Balfour

Subject: Re: Formatting a str as a number - Okay, one more related thing...
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Sat, 31 Aug 2024 15:26 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number - Okay, one more related thing...
Date: 31 Aug 2024 15:26:58 GMT
Organization: Stefan Ram
Lines: 10
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <thousand-20240831162547@ram.dialup.fu-berlin.de>
References: <oRHyO.142039$bV6e.134076@fx08.ams4> <asked-20240825164104@ram.dialup.fu-berlin.de> <combination-20240825164553@ram.dialup.fu-berlin.de> <vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org> <mailman.12.1724794762.2917.python-list@python.org> <dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de AjIinq5hiHWHtAFoM9gKCwOKo9l5UCnE9I4d4rAiq0s3Yq
Cancel-Lock: sha1:tSG+GMIc9AdBW+s0jxanRjCQ0OY= sha256:EmQjF3aE0u02wN5/sHYYHXjk/fweSqL9d6kzbeLVk5E=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

Gilmeh Serda <gilmeh.serda@nothing.here.invalid> wrote or quoted:
>Of course I can do f"{123456:>20_}".replace("_", " "), just thought there
>might be something else my search mojo fails on.

Looks like this "replace" deal is the go-to move, no two ways
about it. If there's some neck of the woods where it's SOP, you
might wanna roll with "locale.format_string". (Whipping up a custom
locale just for kicks is usually more trouble than it's worth.)

Subject: Re: Formatting a str as a number - Okay, one more related thing...
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Sat, 31 Aug 2024 17:00 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number - Okay, one more related thing...
Date: 31 Aug 2024 17:00:11 GMT
Organization: Stefan Ram
Lines: 14
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <str-20240831175845@ram.dialup.fu-berlin.de>
References: <oRHyO.142039$bV6e.134076@fx08.ams4> <asked-20240825164104@ram.dialup.fu-berlin.de> <combination-20240825164553@ram.dialup.fu-berlin.de> <vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org> <mailman.12.1724794762.2917.python-list@python.org> <dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4> <thousand-20240831162547@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de qzn07oCxBUhqtpOCuSftYQk46CzNU9xAuH9OaxyBqg1Bwi
Cancel-Lock: sha1:NivyTgrMxrxro1zi86PyD//DPyI= sha256:u+GAEQJme6i5hNVo7vT68Zb0M0UbxEz+v6+mU31/dJM=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>Looks like this "replace" deal is the go-to move, no two ways
>about it. If there's some neck of the woods where it's SOP, you
>might wanna roll with "locale.format_string". (Whipping up a custom
>locale just for kicks is usually more trouble than it's worth.)

The German DIN 5008 (their fancy-schmancy rules for writing
and formatting) now says you got to use /spaces/ to separate
thousands, and only recommends using periods for cold hard cash.

If you just chill for a hot minute, Python's German locale will
catch up, and you'll be golden.

Subject: Re: Formatting a str as a number - Okay, one more related thing...
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Sat, 31 Aug 2024 17:02 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number - Okay, one more related thing...
Date: 31 Aug 2024 17:02:47 GMT
Organization: Stefan Ram
Lines: 8
Expires: 1 Jul 2025 11:59:58 GMT
Message-ID: <spaces-20240831180208@ram.dialup.fu-berlin.de>
References: <oRHyO.142039$bV6e.134076@fx08.ams4> <asked-20240825164104@ram.dialup.fu-berlin.de> <combination-20240825164553@ram.dialup.fu-berlin.de> <vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org> <mailman.12.1724794762.2917.python-list@python.org> <dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4> <thousand-20240831162547@ram.dialup.fu-berlin.de> <str-20240831175845@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 54QYPrd+cJVj9+F0qDn3cgLWUXDdlxOrHrhYcSMv8d1FmT
Cancel-Lock: sha1:+Y7hZ2/2SXcnt7mb2/OWg2Sq2WM= sha256:5kr1FDbm+IhoGCEkAgxtYRX+X2nZI3DJu1ORXUXiwPM=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
>The German DIN 5008 (their fancy-schmancy rules for writing
>and formatting) now says you got to use /spaces/ to separate
>thousands, and only recommends using periods for cold hard cash.

And, reportedly, ISO 80000, too.

Subject: Re: Formatting a str as a number - Okay, one more related thing...
From: MRAB
Newsgroups: comp.lang.python
Date: Sat, 31 Aug 2024 18:55 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: python@mrabarnett.plus.com (MRAB)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number - Okay, one more related thing...
Date: Sat, 31 Aug 2024 19:55:39 +0100
Lines: 20
Message-ID: <mailman.25.1725130727.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
<dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4>
<9e13c5d9-fda3-4d7d-a87b-3dfd1c51f6ed@mrabarnett.plus.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 2PQWTr/8zQoOLDnJX35wQQLoEAxBg4XHlRvEBIyohrRQ==
Cancel-Lock: sha1:DIAHKjWO9/S9D0Qph2exLihzqMY= sha256:swQFqqU6DlyqSX3ee71bHhs1yPnkADsxoBjKM68ierc=
Return-Path: <python@mrabarnett.plus.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=plus.com header.i=@plus.com header.b=Z3XhzXWg;
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.020
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'aug': 0.07; 'fails': 0.09;
'from:addr:python': 0.09; 'received:192.168.1.64': 0.09; '2024':
0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab':
0.16; 'matter?': 0.16; 'message-id:@mrabarnett.plus.com': 0.16;
'received:plus.net': 0.16; 'wrote:': 0.16; 'to:addr:python-list':
0.20; 'fri,': 0.22; 'space': 0.26; 'else': 0.27; 'header:User-
Agent:1': 0.30; 'python-list': 0.32; 'received:192.168.1': 0.32;
'but': 0.32; 'there': 0.33; 'fill': 0.34; 'header:In-Reply-To:1':
0.34; 'received:192.168': 0.37; 'on.': 0.39; 'something': 0.40;
'search': 0.61; 'format': 0.62; 'received:212': 0.62; 'skip:f 20':
0.75; 'subject:one': 0.76; 'subject:more': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=plus.com; s=042019;
t=1725130540; bh=RvA+dZV4Lj6SygHbU3Kcjd3DPiHGeglSiOeyQdhAgts=;
h=Date:Subject:To:References:From:In-Reply-To;
b=Z3XhzXWgRSj09FPfcbhzJBfe/SjZRDYUKlMZQ2Sb7i3Rfm050/sykiCiBD1HlVoOJ
3FlyqtupniVdWBL8baGK0syfcLxxjqc6YjisG5Lgg2dgu+6ifQwQO6dmtxoeEXJ9Pl
iK8xL+MLkL70NL+qcHn+pNRUcStYvhuduwdvf/d4kk/GlwrK0x8fvl+Wg5Np2eo0Un
gCRzQkVXQNnVxbgqfv+0aVlTmNq7mJMFlN2cAF/eBp1/oR9V9T9CTvk+jK65s4IYsF
/F4bJEht7gsWKncY8ZfAOdm7BsCOatF+Gpg1pRwPwQ/T/mmTYlTx1+QmZ3QIQCpm5G
2dkg6fXH743lw==
X-Clacks-Overhead: "GNU Terry Pratchett"
X-CM-Score: 0.00
X-CNFS-Analysis: v=2.4 cv=JP6YsNKb c=1 sm=1 tr=0 ts=66d3672c
a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17
a=IkcTkHD0fZMA:10 a=8AHkEIZyAAAA:8 a=9BhTC2_CMXAuQcYKMiwA:9 a=QEXdDO2ut3YA:10
a=wNw7CiXM-hcA:10 a=0lgtpPvCYYIA:10
X-AUTH: mrabarnett@:2500
User-Agent: Mozilla Thunderbird
Content-Language: en-GB
In-Reply-To: <tUxAO.85679$fD72.80638@fx06.ams4>
X-CMAE-Envelope: MS4xfJ4WcrCJbmtf7oxs59EhpOE4J9707zWrSiMZf+XwoGmYb2YToC1z+qHQhVixBH+/xvcvCexVuEwML0/NVLnxxldT7axLEetQ8SJ8eDqSME/apwWG4aSp
xKMen99Bnk5copI042Oq+NOKY2CbRDmNTmQGwWMOqDcm5ItyDWWqKgU98PD7piQ4yb45tRm1s7WNVGG54ZftzOa7J19PgSDB0XQ=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <9e13c5d9-fda3-4d7d-a87b-3dfd1c51f6ed@mrabarnett.plus.com>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
<dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4>
View all headers

On 2024-08-31 06:31, Gilmeh Serda via Python-list wrote:
> On Fri, 30 Aug 2024 05:22:17 GMT, Gilmeh Serda wrote:
>
>> f"{int(number):>20,}"
>
> I can find "," (comma) and I can find "_" (underscore) but how about " "
> (space)?
>
> Or any other character, for that matter?
>
> Any ideas?
>
> Of course I can do f"{123456:>20_}".replace("_", " "), just thought there
> might be something else my search mojo fails on.
>
The format is described here:

https://docs.python.org/3/library/string.html#formatspec

A space is counted as a fill character.

Subject: Re: Formatting a str as a number (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Sat, 31 Aug 2024 22:56 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number (Posting On Python-List Prohibited)
Date: Sat, 31 Aug 2024 22:56:01 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <vb0721$162j5$7@dont-email.me>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
<dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4>
<thousand-20240831162547@ram.dialup.fu-berlin.de>
<str-20240831175845@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 01 Sep 2024 00:56:01 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="451ad815162a3f3080e1cdc6c6433f29";
logging-data="1247845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cHlgOKDRPSr6VC0Tpx4Lv"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:Ce3gFjJLofLGFkZvxo67kJk9VSo=
View all headers

On 31 Aug 2024 17:00:11 GMT, Stefan Ram wrote:

> The German DIN 5008 (their fancy-schmancy rules for writing and
> formatting) now says you got to use /spaces/ to separate thousands ...

That was taught to me as the international scientific standard when I was
in secondary school. Along with using a centred dot for the decimal point,
to avoid the confusion with region-specific rules involving full stops and
commas.

Subject: Re: Formatting a str as a number - Okay, one more related thing...
From: dn
Newsgroups: comp.lang.python
Organization: DWM
Date: Mon, 2 Sep 2024 00:33 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Formatting a str as a number - Okay, one more related thing...
Date: Mon, 2 Sep 2024 12:33:16 +1200
Organization: DWM
Lines: 87
Message-ID: <mailman.26.1725237203.2917.python-list@python.org>
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
<dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4>
<9e13c5d9-fda3-4d7d-a87b-3dfd1c51f6ed@mrabarnett.plus.com>
<df34f126-6ff8-4c0d-b4c5-e507cba6d422@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Qrr8Zp3TqvRQ7Iw6bYYtMQwmLm2I84kcSBA/u4Dce2jg==
Cancel-Lock: sha1:/qOMEHKizBCedEirv4ekc41MhZ0= sha256:MojdQefap3wta0fM1EI2PLP58QhdtDlzyq4cwAQL60k=
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=LbTSaDMF; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'aug': 0.07; '"""': 0.09;
'=dn': 0.09; 'example:': 0.09; 'fails': 0.09; 'float': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'portugal': 0.09; 'import': 0.15; '"gnu': 0.16; "(there's":
0.16; '2024': 0.16; 'decimal': 0.16; 'integer': 0.16; 'matter?':
0.16; 'message-id:@DancesWithMice.info': 0.16; 'print(': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'spain':
0.16; 'symbol': 0.16; 'ways.': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.20; 'fri,': 0.22; 'skip:_ 10': 0.22; 'skip:p 30':
0.23; 'space': 0.26; 'else': 0.27; 'old': 0.27; '>>>': 0.28;
'example,': 0.28; 'header:User-Agent:1': 0.30; 'present': 0.30;
'code,': 0.31; 'header:Organization:1': 0.31; 'python-list': 0.32;
'but': 0.32; 'there': 0.33; 'same': 0.34; 'fill': 0.34; 'header
:In-Reply-To:1': 0.34; 'words': 0.35; 'others': 0.37;
'received:192.168': 0.37; 'two': 0.39; 'on.': 0.39; 'something':
0.40; 'usa': 0.60; 'search': 0.61; 'today': 0.61; 'format': 0.62;
'public': 0.63; 'europe': 0.64; 'license': 0.64; 'your': 0.64;
'produce': 0.65; 'look': 0.65; 'skip:f 20': 0.75; 'france': 0.76;
'subject:one': 0.76; 'period': 0.81; 'country': 0.88;
'subject:more': 0.95
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud CCBFA33BB
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1725237200;
bh=Eb91miLlQHnRRgQW7VfkJiq3jT47IPxXf8NrM+9SpWY=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=LbTSaDMF9m3gH7BRst2f1smZM++3f8iOKEuywaQyuCKRmc3mGrrFbYeFiGP/nwnh7
QUy0nsvhQf+2KqktqaY72xbM1tpfJvXkyV0mkOFwnX875538rCqwk97T2DjG1Bgrcg
wPSuMJksbFFX8USzqZf4K9HwhREC03BZw61voUJPaymSxnw7kJpr1QgzaANllIE+VM
QsnpsL3kHXMm1uOlV/GK4O+8ibQfYJIlouyUuEE9/9gA/H9KXeeRgxFXNvpyPavCd1
7NVy6A/EHs3u++jUpGDukgkkmYwNBJUkfTUvq4At/J36LS+QnGysfyDmc7nkz4HJFH
d/P8xrXEW1iwQ==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <9e13c5d9-fda3-4d7d-a87b-3dfd1c51f6ed@mrabarnett.plus.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <df34f126-6ff8-4c0d-b4c5-e507cba6d422@DancesWithMice.info>
X-Mailman-Original-References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
<dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4>
<9e13c5d9-fda3-4d7d-a87b-3dfd1c51f6ed@mrabarnett.plus.com>
View all headers

On 1/09/24 06:55, MRAB via Python-list wrote:
> On 2024-08-31 06:31, Gilmeh Serda via Python-list wrote:
>> On Fri, 30 Aug 2024 05:22:17 GMT, Gilmeh Serda wrote:
>>
>>> f"{int(number):>20,}"
>>
>> I can find "," (comma) and I can find "_" (underscore) but how about " "
>> (space)?
>>
>> Or any other character, for that matter?
>>
>> Any ideas?
>>
>> Of course I can do f"{123456:>20_}".replace("_", " "), just thought there
>> might be something else my search mojo fails on.
>>
> The format is described here:
>
> https://docs.python.org/3/library/string.html#formatspec
>
> A space is counted as a fill character.

Rather than strict formatting, you may be venturing into
"internationalisation/localisation" thinking.

Different cultures/languages present numeric-amounts in their own ways.
For example, a decimal point may look like a dot or period to some
(there's two words for the same symbol from different English-language
cultures!), whereas in Europe the symbol others call a comma is used, eg
123.45 or 123,45 - and that's just one complication of convention...

For your reading pleasure, please review "locales"
(https://docs.python.org/3/library/locale.html)

Here's an example:

Country Integer Float
USA 123,456 123,456.78
France 123 456 123 456,78
Spain 123.456 123.456,78
Portugal 123456 123456,78
Poland 123 456 123 456,78

Here's some old code, filched from somewhere (above web.ref?) and
updated today to produce the above:-

""" PythonExperiments:locale_numbers.py
Demonstrate numeric-presentations in different cultures (locales).
"""

__author__ = "dn, IT&T Consultant"
__python__ = "3.12"
__created__ = "PyCharm, 02 Jan 2021"
__copyright__ = "Copyright © 2024~"
__license__ = "GNU General Public License v3.0"

# PSL
import locale

locales_to_compare = [
( "USA", "en_US", ),
( "France", "fr_FR", ),
( "Spain", "es_ES", ),
( "Portugal", "pt_PT", ),
( "Poland", "pl_PL", ),
]

print( "\n Country Integer Float" )
for country_name, locale_identifier in locales_to_compare:
locale.setlocale( locale.LC_ALL, locale_identifier, )
print( F"{country_name:>10}", end=" ", )
print(
locale.format_string("%10d", 123456, grouping=True, ),
end="",
)
print( locale.format_string("%15.2f", 123456.78, grouping=True, ) )

--
Regards =dn

--
Regards,
=dn

Subject: Re: Formatting a str as a number - Okay, one more related thing...
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Tue, 3 Sep 2024 16:16 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!weretis.net!feeder8.news.weretis.net!npeer.as286.net!npeer-ng0.as286.net!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx05.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Re: Formatting a str as a number - Okay, one more related thing...
Newsgroups: comp.lang.python
References: <oRHyO.142039$bV6e.134076@fx08.ams4>
<asked-20240825164104@ram.dialup.fu-berlin.de>
<combination-20240825164553@ram.dialup.fu-berlin.de>
<vYqzO.8$fip4.7@fx09.ams4> <4Wtgt14jXFznWHr@mail.python.org>
<mailman.12.1724794762.2917.python-list@python.org>
<dGcAO.20275$Ic_6.799@fx01.ams4> <tUxAO.85679$fD72.80638@fx06.ams4>
<thousand-20240831162547@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.160 (Toresk; 9d04e24)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 14
Message-ID: <ODGBO.91191$1pff.46403@fx05.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Tue, 03 Sep 2024 16:16:46 GMT
X-Received-Bytes: 1530
View all headers

On 31 Aug 2024 15:26:58 GMT, Stefan Ram wrote:

> Looks like this "replace" deal is the go-to move,

Yep, looks like it from the rest of the replies.

Thanks to all participants.

--
Gilmeh

"You're just the sort of person I imagined marrying, when I was little...
except, y'know, not green... and without all the patches of fungus." --
Swamp Thing

1

rocksolid light 0.9.8
clearnet tor