On Tuesday, August 19, 2014 7:15:54 PM UTC+2, Rustom Mody wrote: > On Tuesday, August 19, 2014 10:31:03 PM UTC+5:30, Laurent Pointal wrote: > > > raphinou wrote: > > > > > > Hi, > > > > I'm using pyyaml, and need some values in a yaml files to be dynamic, > > > for > > > > example somethin like: > > > > filename: /tmp/backup_{% time.strftime('%Y-%m-%d') }.tgz > > > > Is there a simple way to achieve this? (Eg with a templating system > > > that > > > > would first handle the template parts from the yaml file) > > > > Thanks > > > > > I used jinja2 templating system to build (render) the yaml string > > > representation before processing it with yaml. > > > > > But for a simple use, maybe a direct keyword replacement is easier (but > > > gives less control in the template, more in the code). > > > > Python's format operator -- '%' or the modern variant -- > > is a mini-templating language: > > > > open(templatefile).read() % substitutions
Note that in my example the content to be inserted is not the result of a variable substitution, but the result of a call to a function. format doesn't seem to work in this case. And jinja2 doesn't seem to provide a straight forward solution either Thx -- https://mail.python.org/mailman/listinfo/python-list