Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2573
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; 'indeed,': 0.07; 'terry': 0.07; 'bool': 0.09; 'doubles': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; '>>>': 0.12; 'def': 0.13; 'wrote:': 0.14; '"class': 0.16; '*args,': 0.16; 'brackets,': 0.16; 'post:': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'reedy': 0.16; 'subject:set': 0.16; 'code': 0.22; 'convert': 0.22; 'tried': 0.27; 'skip:( 20': 0.31; 'from:addr:web.de': 0.31; 'import': 0.32; 'to:addr:python- list': 0.32; 'creates': 0.33; 'header:X-Complaints-To:1': 0.34; 'that,': 0.35; 'print': 0.35; 'skip:. 10': 0.36; 'but': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'could': 0.39; 'header:Mime-Version:1': 0.39; 'header:Received:5': 0.40; 'double': 0.69; 'subject:other': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: proposal to allow to set the delimiter in str.format to something other than curly bracket |
| Date | Mon, 04 Apr 2011 18:18:08 +0200 |
| Organization | None |
| References | <a227e6f7-45ae-4404-973f-b69adf156440@d19g2000yql.googlegroups.com> <mailman.180.1301894287.2990.python-list@python.org> <902f640f-7540-4309-bb54-a1e71d86bb87@d28g2000yqc.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084ae35.dip.t-dialin.net |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7.1301933897.9059.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1301933897 news.xs4all.nl 81478 [::ffff:82.94.164.166]:41589 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:2573 |
Show key headers only | View raw
Alia Khouri wrote:
> Terry Reedy wrote:
>
>> Just double the brackets, just as one doubles '\\' to get '\' in a
>> string.
>>
>> >>> "class {0}Model {{ public bool IsModel(){{ returntrue;
>> }}}}".format('My')
>>
>> 'class MyModel { public bool IsModel(){ returntrue; } }'
>>
>
> Indeed, I tried that, but it means I have to double bracket all the
> csharp code which just creates more work for me.
You could automatically convert from a custom format like that in your
original post:
import re
_lookup = {
"[[": "{",
"]]": "}",
"{": "{{",
"}": "}}",
}
def _substitute(m):
return _lookup[m.group()]
def custom_format(template, *args, **kw):
return (re.compile(r"\[\[|]]|\{|\}")
.sub(_substitute, template)
.format(*args, **kw))
code = "class [[0]]Model { public bool IsModel(){ return a[42] || true; } }"
print custom_format(code, "My")
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
proposal to allow to set the delimiter in str.format to something other than curly bracket Alia Khouri <alia_khouri@yahoo.com> - 2011-04-03 03:07 -0700
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Corey Richardson <kb1pkl@aim.com> - 2011-04-03 06:53 -0400
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Alia Khouri <alia_khouri@yahoo.com> - 2011-04-03 05:17 -0700
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Terry Reedy <tjreedy@udel.edu> - 2011-04-04 01:17 -0400
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Alia Khouri <alia_khouri@yahoo.com> - 2011-04-04 08:42 -0700
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Peter Otten <__peter__@web.de> - 2011-04-04 18:18 +0200
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Alia Khouri <alia_khouri@yahoo.com> - 2011-04-04 13:45 -0700
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Neil Cerutti <neilc@norwich.edu> - 2011-04-05 13:45 +0000
Re: proposal to allow to set the delimiter in str.format to something other than curly bracket Alia Khouri <alia_khouri@yahoo.com> - 2011-04-04 14:32 -0700
csiph-web