Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:parsing': 0.09; 'wrote:': 0.15; 'brackets': 0.16; 'from:addr:free.fr': 0.16; 'received:free.fr': 0.16; 'pm,': 0.16; '>>>': 0.16; 'command': 0.19; 'header:In-Reply-To:1': 0.22; 'parse': 0.23; 'thu,': 0.28; '+0200,': 0.30; 'nested': 0.30; 'value)': 0.30; "won't": 0.32; 'ps:': 0.32; 'to:addr:python-list': 0.34; 'header:User-Agent:1': 0.34; 'nobody': 0.34; 'received:192': 0.38; 'subject:: ': 0.38; 'skip:t 40': 0.38; 'to:addr:python.org': 0.39; '06:37': 0.84 Date: Thu, 28 Jul 2011 19:51:10 +0200 From: Karim User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: shlex parsing References: <4e3184d3$0$29530$426a74cc@news.free.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311875478 news.xs4all.nl 23956 [2001:888:2000:d::a6]:57202 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10468 Just a little modification: >>> tuple([(option, value) for option,value in zip(optionlist[0::2],optionlist[1::2])]) == tuple(zip(optionlist[0::2],optionlist[1::2])) True Indeed: tuple(zip(optionlist[0::2],optionlist[1::2])) shorter than: tuple([(option, value) for option,value in zip(optionlist[0::2],optionlist[1::2])]) Karim PS: I am from Grenoble, which place in France are from? On 07/28/2011 06:37 PM, Nobody wrote: > On Thu, 28 Jul 2011 17:48:34 +0200, Web Dreamer wrote: > >>> I would like to parse this TCL command line with shlex: >>> >>> '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG' >>>>> s = s.replace('[','"[') >>>>> s = s.replace(']',']"') > Note that this approach won't work if you have nested brackets or braces. > That would require a real parser. >