Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Ervin =?utf-8?Q?Heged=C3=BCs?= Newsgroups: comp.lang.python Subject: String format - resolve placeholders names Date: Fri, 20 Nov 2015 15:52:27 +0100 Lines: 35 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Trace: news.uni-berlin.de 6PcrQXazgHb6fMnqYgDcNwWgTu2yRJ3iiw6DbcjdNk5g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'method:': 0.09; 'python': 0.10; 'received:io': 0.16; 'received:psf.io': 0.16; 'result:': 0.16; 'subject:String': 0.16; 'string': 0.17; 'exists': 0.18; 'try:': 0.18; 'keyerror:': 0.22; 'this:': 0.23; 'thanks,': 0.24; 'header:User-Agent:1': 0.26; 'except': 0.34; 'received:google.com': 0.35; 'possible,': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr :python-list': 0.36; 'names': 0.38; 'hi,': 0.38; 'to:addr:python.org': 0.40; '(direct)': 0.84; 'received:86': 0.93; 'received:hu': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=BsyT4y9WrOGZDqRwwKojHLTKiDfXttppZOqOWJlrgJs=; b=t7oX9JkIhboECgpUOSNjW4N4QDat51DiaMl3Mc1eiw8jn1IcN8ycLzR3HDDKKUEEb2 Lq9GoNttLmHAKW9z7JwHXy212Verblolx5EDQDfLSvHd1q+tsOIAkltZffROwTVoDPq5 YiccOrCjH0jB70lIC1gwadsAzhRmvZESXtc8suVtJAdKdaytaDfWTE1zePvVSGuAoB7p HezKjpSVOsqtd4vbb1GjYYiJ3t2v/5Qivxj8qzdGG3OvuDeKxnboO7l22ZShpOGx99f2 31jUcBYMs+/NkJkStjRjTNKZIYropWhuC2nkkOvgjjgiNL7gCEwSwGCPhjVweFvKR3fQ wlwg== X-Received: by 10.28.145.134 with SMTP id t128mr352836wmd.64.1448031135683; Fri, 20 Nov 2015 06:52:15 -0800 (PST) Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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:99155 Hi, 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? There is a know method: d1 = {'who1': "Adam", 'what1': "ants"} try: s.format(**d1) except KeyError: print("keyword missing") (gives 'keyword missing' as result). But is there any other (direct) way, which keywords exists in string? Thanks, a.