4 ms·
If you want format strings with sensible placeholders, you end up with something like "Hello {person}, it's a {weather} day".format(person=person, weather=
by philh 12y ago
If you want format strings with sensible placeholders, you end up with something like
"Hello {person}, it's a {weather} day".format(person=person, weather=weather)
The list of variables (person, weather) shows up three times.
Somewhat off-topic, a similar problem shows up when you have a bunch of related functions, all taking a particular kwarg (or kwargs), and calling each other. Like
def foo(arg, conf1=None, conf2=None):
bar(arg+2, conf1=conf1, conf2=conf2) # eww :(
def bar(arg, conf1=None, conf2=None):
# etc.
A neat thing that perl6 has is syntax for "keyword argument whose value is found in the variable of the same name". So the equivalent of that line could be written
bar($arg+2, :conf1($conf1), :conf2($conf2))
but it could also be
bar($arg+2, :$conf1, :$conf2)