Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python': 0.08; 'subject:string': 0.09; 'pm,': 0.10; 'wrote:': 0.14; 'library': 0.15; '2.6,': 0.16; 'slicing': 0.16; 'str.format()': 0.16; 'string:': 0.16; '\xa0to': 0.16; 'cc:addr:python-list': 0.17; 'mon,': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'parse': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'versions': 0.23; 'extract': 0.25; 'match': 0.26; 'received:209.85.161': 0.26; 'string': 0.26; 'message-id:@mail.gmail.com': 0.28; 'import': 0.29; 'version': 0.29; 'cc:addr:python.org': 0.30; 'optimal': 0.30; 'subject:format': 0.30; "skip:' 10": 0.32; 'expression': 0.32; 'skip:\xa0 30': 0.32; 'question': 0.34; 'regular': 0.34; 'there': 0.35; '2.6': 0.35; '8bit%:3': 0.35; 'using': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; '20,': 0.37; 'could': 0.38; 'subject:from': 0.38; 'but': 0.38; 'data': 0.38; 'earlier': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'received:209': 0.39; 'johnson': 0.39; 'serving': 0.66; '12:14': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=Pkl9xUG6jFwjSvTWW4E80JgpeL81ifv59TyepokQrYI=; b=iZPH3pocAn+S71mHIZstZk/lBmHASq3LoEy0R3deVxe+qE93oK4ekwTPOzRGvuXgPj S79t1y2BUmam4w18bozIwezumN8r/krVteqKpY6Nwp2m1QfVKmakuwcmBydxk9dtnHG4 EoMDgxzPsZukPMAo12mhWrVl6x2fhJMLNvQ0o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=I6wgvzcpKj29Juiq6uhrqOJNTRFKyOUThYKW6gJ7dWq693KEafEidV85mu4zQI5Nay kqtJ5V95JgxeoCatFPn1NGunMtrWF/BKA8utKO5/VWorZHUMzC7wF7HyHt04ILp7f5eK P3owh3Xckbmixx7JyQa6/uqK+y1R1tL2B6gtw= MIME-Version: 1.0 In-Reply-To: <20110620181446.GI1971@johnsons-web.com> References: <20110620181446.GI1971@johnsons-web.com> From: Ian Kelly Date: Mon, 20 Jun 2011 13:34:46 -0600 Subject: Re: Parsing a dictionary from a format string To: Tim Johnson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python ML X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 23 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308598519 news.xs4all.nl 49174 [::ffff:82.94.164.166]:40367 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8025 On Mon, Jun 20, 2011 at 12:14 PM, Tim Johnson wrote: > Currently using python 2.6, but am serving some systems that have > older versions of python (no earlier than. > Question 1: > =A0With what version of python was str.format() first implemented? 2.6 > Question 2: > =A0Given the following string: > =A0 =A0S =3D 'Coordinates: {latitude}, {longitude}' > =A0Is there a python library that would provide an optimal way > =A0 =A0to parse from S the following > =A0{'latitude':"",'longitude':""} > =A0? import re match =3D re.match('^Coordinates: (.+), (.+)$', S) if match: data =3D {'latitude': match.group(1), 'longitude': match.group(2)} Or you could use string methods and slicing to extract the figures, which would be faster than the regular expression machinery.