Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76569 > unrolled thread
| Started by | raphinou@gmail.com |
|---|---|
| First post | 2014-08-19 07:32 -0700 |
| Last post | 2014-08-20 18:59 +0200 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.python
dynamic values in yaml raphinou@gmail.com - 2014-08-19 07:32 -0700
Re: dynamic values in yaml Laurent Pointal <laurent.pointal@laposte.net> - 2014-08-19 19:01 +0200
Re: dynamic values in yaml Rustom Mody <rustompmody@gmail.com> - 2014-08-19 10:15 -0700
Re: dynamic values in yaml raphinou@gmail.com - 2014-08-19 23:50 -0700
Re: dynamic values in yaml Rustom Mody <rustompmody@gmail.com> - 2014-08-20 00:36 -0700
Re: dynamic values in yaml Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-20 09:59 +0100
Re: dynamic values in yaml Laurent Pointal <laurent.pointal@laposte.net> - 2014-08-20 18:59 +0200
| From | raphinou@gmail.com |
|---|---|
| Date | 2014-08-19 07:32 -0700 |
| Subject | dynamic values in yaml |
| Message-ID | <c3aefcb3-7a4f-4dab-98b5-000defd17f03@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Laurent Pointal <laurent.pointal@laposte.net> |
|---|---|
| Date | 2014-08-19 19:01 +0200 |
| Message-ID | <53f382cf$0$1998$426a74cc@news.free.fr> |
| In reply to | #76569 |
raphinou@gmail.com 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).
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-08-19 10:15 -0700 |
| Message-ID | <244efc25-db3c-4a7a-8e2a-e49b7185b9c8@googlegroups.com> |
| In reply to | #76578 |
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
[toc] | [prev] | [next] | [standalone]
| From | raphinou@gmail.com |
|---|---|
| Date | 2014-08-19 23:50 -0700 |
| Message-ID | <3c546ce4-0a33-499b-a27a-1ccf4d774cf6@googlegroups.com> |
| In reply to | #76579 |
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
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-08-20 00:36 -0700 |
| Message-ID | <f92528a1-fd18-42b8-8a37-04e54261d02b@googlegroups.com> |
| In reply to | #76639 |
On Wednesday, August 20, 2014 12:20:21 PM UTC+5:30, raph...@gmail.com wrote:
> 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
Dunno jinja
In Cheetah you can use <%= arbitrary python expression %>
http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000650000000000000000
PS Please read this
https://wiki.python.org/moin/GoogleGroupsPython
Else some folks here get very irritated
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-08-20 09:59 +0100 |
| Message-ID | <mailman.13192.1408525211.18130.python-list@python.org> |
| In reply to | #76639 |
On 20/08/2014 07:50, raphinou@gmail.com wrote: Would you please access this list via https://mail.python.org/mailman/listinfo/python-list or read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing and single line paragraphs, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Laurent Pointal <laurent.pointal@laposte.net> |
|---|---|
| Date | 2014-08-20 18:59 +0200 |
| Message-ID | <53f4d3d9$0$2927$426a74cc@news.free.fr> |
| In reply to | #76639 |
raphinou@gmail.com wrote:
> 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
Yoy may try it, setup an environment (dictionnary) with 'time' mapped
to the time module, and render the template using this environment.
Normally Jinja2 manage namespaces and function call.
Your template would be:
filename: /tmp/backup_{{ time.strftime('%Y-%m-%d') }}.tgz
And the environment for rendering simply:
import time
env = { time: time }
http://jinja.pocoo.org/docs/templates/#other-operators
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web