So apparently, Python will allow
'%s %(var)s' % {'var': 'x'}
which produces
"{'var': 'x'} x"
I’m writing something where I basically want python’s named placeholder substitution features only. Is there any way to detect a mix of named and positional placeholders?
EDIT: The context of this is that I’m writing something that’s sort of a templating tool. After writing a bunch of stuff with %(named)s all over the place, you then call template.substitute(dict) to go and replace everything. I’m trying to prevent the case where people leave %[srfd,etc] in the string(because they forgot to interpolate or something) by throwing an error if it’s been left there.
The str.__mod__ builtin function isn’t reprogrammable. There isn’t a way to selectively turn-off some of its features.
You could however use a regex to locate the positional placeholders and escape them prior to string interpolation: