[Python-ideas] String interpolation: environment variables, command substitution

Paul Moore p.f.moore at gmail.com
Wed Aug 26 20:58:29 CEST 2015


On 26 August 2015 at 19:20, Mike Miller <python-ideas at mgmiller.net> wrote:
> One of the remaining questions for the string interpolation subject is
> whether to allow for easy access to environment variables and output-capture
> of external processes (aka command-substitution) as bash does.
>
> While incredibly useful in use-cases such as shell-script replacements, the
> functionality is perceived to be, if not dangerous.  More so than arbitrary
> expressions?  Given that we are talking about string literals and not input,
> I'm not sure, so am looking for feedback.
>
> The idea is not unheard of in Python, there was a module that captured
> process output called commands in the old days, which was superseded at some
> point by subprocess.check_output() I believe.

This seems like a really good idea for an external module but I see no
reason why it is important enough to deserve built in syntax in the
core language.

Note that cross platform issues are going to be a major issue:

* $HOME is "the wrong way to do it" - Windows has no HOME env
variable. The right way is os.path.expanduser("~")
* $(/bin/ls) is the wrong way - os.listdir(".") is the right way
(windows has no ls command)

Making it easy to write platform specific code when it's not needed is
as much of an antipattern as making it easy to write insecure code
IMO.

Paul


More information about the Python-ideas mailing list