mercredi 25 mars 2015

How to create strings with html and placeholders for values in python

I need to pass variables to an HTML code that is inside a variable, so I need placeholders.



href = 'http://www.theverge.com'
alt = 'Yet another alt attribute!'

html_string = '<a href="?" alt="?" ></a>'


I've used ? ? where the placeholders should be placed...


I want to define html_string outside of the scope of these variables. So I need a way to set the placeholders first, then add to them the variables.


I'm NOT asking for this:



html_string = '<a href="' + href + '" alt="' + alt + '" ></a>'

Aucun commentaire:

Enregistrer un commentaire