On 2/11/2022 5:33 PM, Ricky Teachey wrote:
On Fri, Feb 11, 2022 at 4:58 PM MRAB <pyt...@mrabarnett.plus.com> wrote:

    On 2022-02-11 20:05, Ricky Teachey wrote:
    > Just had a thought kernel: what if there were an f-string
    mini-language
    > directive to grab environment variables and expand user paths? That
    > seems to me like it could be even more useful beyond just
    working with
    > paths.
    >
    > Maybe something like:
    >
    > f"{my_var:$}"
    >
    > This would return the same as os.path.expandvars("$my_var")
    >
    No, that would be the value of the Python variable 'my_var' with the
    format string "$".


well right now $ is not a valid format string for f-strings.

Off topic: there are no characters that are invalid format strings, except '!' and ':'. For example, datetime allows anything, since it's passed on to strftime:

>>> from datetime import date
>>> f'{datetime.now():This is a test $@$&*()}'
'This is a test $@$&*()'

Or:

>>> class F:
...   def __format__(self, fmt):
...     if fmt == '$':
...       return 'dollar'
...     return 'something else'
...
>>> f'{F():$}'
'dollar'
>>> f'{F():x}'
'something else'

Eric
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JGZAU2A7EQIMTOWPTMTNRLRIBDTK4BJX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to