Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'infinite': 0.07; 'path,': 0.07; 'python': 0.08; 'loop.': 0.09; 'oh,': 0.09; 'relies': 0.09; 'wrote:': 0.15; 'lambda': 0.16; 'scope.': 0.16; 'ugly.': 0.16; 'cc:addr:python-list': 0.16; 'pm,': 0.16; 'subject:list': 0.16; 'cc:2**0': 0.21; 'loop': 0.22; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'received:209.85.220': 0.25; 'thu,': 0.28; 'message-id:@mail.gmail.com': 0.28; "skip:' 30": 0.29; 'cc:addr:python.org': 0.30; 'kelly': 0.30; 'print': 0.32; "won't": 0.32; 'list': 0.32; 'does': 0.32; 'subject: ?': 0.35; 'skip:o 20': 0.36; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'received:209': 0.40; 'subject:skip:o 10': 0.84; 'something.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=ETUhUmC/VK3VaJlEG292gydSvmhLQojenik9eDKPuX8=; b=GcEbHQappMRfycWawXd3HXxQhqwt+UH2IM3aQttNpT9JxVOoxFZDn69kpQFGvihyOV qh9z125zNqrlA8HFsg9KjWM4w39QFyy9sKTU/kuHzE8AVxir6u9itKZpvzeEPOO2LGYM z9D3BAiblzyBJZmTJK1n1LzUO/ggsUSgA9ydM= MIME-Version: 1.0 In-Reply-To: References: <1954d20a-7177-45d9-afa0-e98b171b2822@w27g2000yqk.googlegroups.com> From: Ian Kelly Date: Thu, 28 Jul 2011 15:04:52 -0600 Subject: Re: list comprehension to do os.path.split_all ? To: gry Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311887125 news.xs4all.nl 23938 [2001:888:2000:d::a6]:52522 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10478 On Thu, Jul 28, 2011 at 2:47 PM, Ian Kelly wrote: > On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly wrote: >> path =3D '/home/gyoung/hacks/pathhack/foo.py' >> parts =3D [part for path, part in iter(lambda: os.path.split(path), ('/'= , ''))] >> parts.reverse() >> print parts >> >> But that's horrendously ugly. =A0Just write a generator with a while >> loop or something. > > Also, note that if the path does not start with '/', the result will > be an infinite loop. Oh, and this won't work at all in Python 3, because it relies on the lambda having access to the list comprehension scope.