X-Received: by 10.182.60.135 with SMTP id h7mr17298213obr.18.1408468555433; Tue, 19 Aug 2014 10:15:55 -0700 (PDT) X-Received: by 10.50.2.6 with SMTP id 6mr182486igq.10.1408468555290; Tue, 19 Aug 2014 10:15:55 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!r2no2979854igi.0!news-out.google.com!ef6ni1904igb.0!nntp.google.com!uq10no2048762igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Tue, 19 Aug 2014 10:15:54 -0700 (PDT) In-Reply-To: <53f382cf$0$1998$426a74cc@news.free.fr> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=59.95.7.75; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui NNTP-Posting-Host: 59.95.7.75 References: <53f382cf$0$1998$426a74cc@news.free.fr> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <244efc25-db3c-4a7a-8e2a-e49b7185b9c8@googlegroups.com> Subject: Re: dynamic values in yaml From: Rustom Mody Injection-Date: Tue, 19 Aug 2014 17:15:55 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.python:76579 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