Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: String format - resolve placeholders names Date: Fri, 20 Nov 2015 16:53:47 +0100 Organization: None Lines: 22 Message-ID: References: <20151120145227.GB13994@arxnet.hu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: news.uni-berlin.de ev7GAZG5P9D4CxowRuqhhwWxSUe2yOE+5v1pTLo+pYIw== Return-Path: 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; "'',": 0.07; 'none)': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; "('',": 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'result:': 0.16; 'subject:String': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'this:': 0.23; 'import': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:s 30': 0.31; 'possible,': 0.35; 'item': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'names': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd871b.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99158 Ervin Hegedüs wrote: > Python has a good string formatter, eg. I can do this: > > s = "{who} likes {what}" > d = {'who': "Adam", 'what': "ants"} > s.format(**d) > > result: > 'Adam likes ants' > > Is it possible, and if yes, how to resolve the placeholders names > in string? >>> import string >>> for item in string.Formatter().parse("{who} likes {what}"): ... print(item) ... ('', 'who', '', None) (' likes ', 'what', '', None)