%%(%s)s mean in python

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Wed Oct 29 11:12:44 EDT 2014


Am 29.10.2014 07:02 schrieb satishmlmlml at gmail.com:

> What does %%(%s)s mean in Python?

Weird question, as this has nothing to do with the code you just posted.

In general, what comes up to my mind, is that it is a format string to 
build another format string.

Example:

metafmt = '%%(%s)s'
fieldname = 'myfield'
fmt = metafmt % fieldname
# Now we have a fmt as if it was assigned with '%(myfield)s':
# %% -> %, %s -> myfield.

d = {fieldname: 'my content'}

print fmt % d
# this now prints the given field - which is noted in fieldname -
# from the given dict d.



More information about the Python-list mailing list