How do you make the following code work?
example = "%%(test)%" % {'test':'name',}
print example
Where the desired output is "%name%"
Thanks
How do you make the following code work?
example = "%%(test)%" % {'test':'name',}
print example
Where the desired output is "%name%"
Thanks
example = "%%%(test)s%%" % {'test':'name',}
print example
%(key)s
is a placeholder for a string identified by key
. %%
escapes %
when using the %
operator.
An alternative is to use the new Advanced String Formatting
>>> example = "%{test}%".format(test="name")
>>> print example
%name%