n00b question: Possible to pass lists to a Template class?

W

Wells

Is it possible to pass a list to the Template.substitute method and
use that in the template, like so..

g = string.Template(gametemplate)
print g.substitute(recap = "none", winner = game["winner"], loser =
game["loser"])

Then in the template...

<b>winner.team

Where winner.team would be the value of game["winner"]["team"].

Thanks!
 
W

Wells

Is it possible to pass a list to the Template.substitute method and
use that in the template, like so..

g = string.Template(gametemplate)
print g.substitute(recap = "none", winner = game["winner"], loser =
game["loser"])

Then in the template...

<b>winner.team

Where winner.team would be the value of game["winner"]["team"].

Thanks!

Sorry, I meant dicts, not lists. Like I said, n00b question.
 
R

Rhodri James

Is it possible to pass a list to the Template.substitute method and
use that in the template, like so..

g = string.Template(gametemplate)
print g.substitute(recap = "none", winner = game["winner"], loser =
game["loser"])

Then in the template...

<b>winner.team

Where winner.team would be the value of game["winner"]["team"].

Thanks!

Sorry, I meant dicts, not lists. Like I said, n00b question.

Basically, no. Substituted values are effectively put into the
template with '%s' substitution, so you'll just get a string
representation of your dictionary. You could play around with
defining your own custom Template class, but it's probably not
worth the effort.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top