Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python : template var without space

in python, I try use templates

 from string import Template
 s = Template("hello $world")
 print s.substitute(world="Stackoverflow")

ok, but, In the template I need concatenate a string without space, example

 s = Template("a small number : $number e6")
 print s.substitute(number=5)

I need a small number : 5e6 as output, without white space between 5 and e6.

like image 494
JuanPablo Avatar asked Apr 18 '13 16:04

JuanPablo


1 Answers

Use curly braces around the pattern:

Template("a small number : ${number}e6")

Result:

>>> Template("a small number : ${number}e6").substitute(number=5)
'a small number : 5e6'
like image 180
Martijn Pieters Avatar answered Oct 09 '22 23:10

Martijn Pieters