Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70436
| References | <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> |
|---|---|
| Date | 2014-04-21 08:41 +1000 |
| Subject | Re: how to string format when string have { |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9389.1398033695.18130.python-list@python.org> (permalink) |
On Mon, Apr 21, 2014 at 8:34 AM, Mariano DAngelo
<marianoa.dangelo@gmail.com> wrote:
> And I want to format like this:
>
> context = {
> "project_name":project_name,
> "project_url":project_url,
> }
>
> nginx_conf.format(**context)
>
>
> but since the string have { i can't.
> Is there a way to solve this?
Are you in full control of the source string? You can escape the
braces as explained here:
https://docs.python.org/3.4/library/string.html#format-string-syntax
If you're not in full control (eg if it comes from a user's input), or
if you don't like the idea of doubling all your braces, you could
switch to percent-formatting, or some other form of interpolation. But
the easiest would be to simply escape them.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to string format when string have { Mariano DAngelo <marianoa.dangelo@gmail.com> - 2014-04-20 15:34 -0700
Re: how to string format when string have { Chris Angelico <rosuav@gmail.com> - 2014-04-21 08:41 +1000
Re: how to string format when string have { Tim Chase <python.list@tim.thechases.com> - 2014-04-20 18:43 -0500
Re: how to string format when string have { Peter Otten <__peter__@web.de> - 2014-04-21 10:51 +0200
Re: how to string format when string have { Chris Angelico <rosuav@gmail.com> - 2014-04-21 18:56 +1000
csiph-web