Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '21,': 0.07; 'context': 0.07; 'string': 0.09; 'escape': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'braces': 0.16; 'braces,': 0.16; "can't.": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:format': 0.16; 'subject:when': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'mon,': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'switch': 0.26; 'this:': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'explained': 0.31; "user's": 0.31; 'url:python': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:org': 0.36; 'easiest': 0.38; 'url:library': 0.38; 'solve': 0.60; 'full': 0.61; 'url:3': 0.61; 'simply': 0.61; "you're": 0.61; 'here:': 0.62; 'url:4': 0.69; 'subject:have': 0.80; 'doubling': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=53cLM0mEwWLemWeSdaxR62kN0LSp6JA2RnVM/Dr/IV0=; b=rvzZIxA2dHJnN+L2kOrTea7/E9NdN0YGkGWURM6VIMBCeCTFLd8cKtuoXTv7uyQm7d 5kOBfg9we09ingmCTlaD437ROCtYGaCbatXoJQa8BP+pKMx04xLPVhlifTMcT92ZKYNP dfUN0hYS26OBJSfDznuPYOP+jTx2ttllmlkGMCTn5sLI9O1UnRDWmoLQpTg+rb+ijKjI T0R2RKEjvvp8Qu8aHsHSLaj5J+/FJt/A6+FwgGy4OgNh2T/qHsSmF2oHuVznIX4TBIQV 0+nB9b39/Gj86JHMlLbe4mUF4VM6Ef1LswWT/7+OaR0HTuk2e9DcYltpOGWENpgGXa8u F+Pw== MIME-Version: 1.0 X-Received: by 10.52.251.199 with SMTP id zm7mr23041038vdc.21.1398033687487; Sun, 20 Apr 2014 15:41:27 -0700 (PDT) In-Reply-To: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> References: <2075921a-dd3e-4788-86fb-e751ad98ee0e@googlegroups.com> Date: Mon, 21 Apr 2014 08:41:27 +1000 Subject: Re: how to string format when string have { From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398033695 news.xs4all.nl 2876 [2001:888:2000:d::a6]:53526 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70436 On Mon, Apr 21, 2014 at 8:34 AM, Mariano DAngelo 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