mpen mpen - 2 years ago 126
Python Question

String formatting named parameters?

I know it's a really simple question, but I have no idea how to google it.

how can I do

print '<a href="%s">%s</a>' % (my_url)

So that
is used twice? I assume I have to "name" the
and then use a dict in the params, but I'm not sure of the proper syntax?

just FYI, I'm aware I can just use
twice in the params, but that's not the point :)

Answer Source
print '<a href="%(url)s">%(url)s</a>' % {'url': my_url}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download