• Re: Formatting a str as a number

    From Gilmeh Serda@21:1/5 to Grant Edwards on Fri Aug 30 05:22:17 2024
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gilmeh Serda@21:1/5 to Stefan Ram on Fri Aug 30 05:25:40 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gilmeh Serda@21:1/5 to Gilmeh Serda on Sat Aug 31 05:31:05 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)