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. what i'm
suggesting is to add $ to the format spec mini-languagem and have the
result be an expanded environment variable value.

but you're right, i guess it would apply this to the *contents *of the
variable my_var, not the STRING my_var. so maybe the spelling would need to
use a nested quotation, like this:

f"{'my_var':$}"

this would be the same as os.path.expandvars("$my_var")

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
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/M73QONQ3HHC2WZN4R657SUDWHWM5L6VK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to