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.056 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; ';-)': 0.12; 'wrote:': 0.15; 'filenames': 0.16; 'received:131': 0.16; 'univ.': 0.16; 'wien,': 0.16; 'pm,': 0.16; '>>>': 0.16; 'subject:list': 0.16; 'this?': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '(or': 0.25; "didn't": 0.29; 'michael': 0.32; "skip:' 10": 0.32; 'to:addr:python-list': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'subject: ?': 0.35; 'charset:us-ascii': 0.36; 'another': 0.38; 'subject:: ': 0.38; 'think': 0.38; 'put': 0.38; 'skip:s 20': 0.39; 'to:addr:python.org': 0.39; 'skip:+ 10': 0.66; 'materials': 0.69; 'spaces': 0.73; 'subject:skip:o 10': 0.84; 'voice:': 0.84 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=univie.ac.at; s=rev2; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date; bh=t5u5xX5RrE8UsDiwCwpR4rrLIyLijgG5r2+CQzeRlG0=; b=CtniOFyCHs7kFDajqkcJDAli/s6pRMiSM0TpyqR5NecVf7pJINKhHq/OpKHq5Me8GxOEbb9fE31fwogKK2izDeWhqOWxSxg/82CRB+lEjV0HcRWy9a+SFghe7VbCNHaHy0gYp/C5LwEwGpwj6DyfB3vQgeeHiaberJj4bomgxnc=; Date: Sun, 31 Jul 2011 07:40:30 +0200 From: Michael Poeltl To: python-list@python.org Subject: Re: list comprehension to do os.path.split_all ? References: <1954d20a-7177-45d9-afa0-e98b171b2822@w27g2000yqk.googlegroups.com> <879a920c-d06a-4413-9566-6c9f0b737235@glegroupsg2000goo.googlegroups.com> <4E33169E.90307@web.de> <20110730002315.GA799@horus.cms.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Univie-Virus-Scan: scanned by ClamAV on joan.univie.ac.at 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312090839 news.xs4all.nl 23942 [2001:888:2000:d::a6]:49545 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10615 * Michael Torrie [2011-07-31 03:44]: > On Jul 29, 2011 6:33 PM, "Michael Poeltl" > wrote: > > > > what about this? > > >>> ' '.join('/home//h1122/bin///ghi/'.split('/')).split() > > ['home', 'h1122', 'bin', 'ghi'] > > >>> > > Doesn't work on filenames with spaces in them. you are right; me, I never put spaces into my filenames and so I didn't think of this possibility. so there is another idea, which will not work on dirnames 'with spacs in them' ;-) >>> p = '/path//to///file/i am a file' >>> ' '.join(os.path.split(p)[0].split('/')).split().__add__([os.path.split(p)[1]]) ['path', 'to', 'file', 'i am a file'] >>> -- Michael Poeltl Computational Materials Physics voice: +43-1-4277-51409 Univ. Wien, Sensengasse 8/12 fax: +43-1-4277-9514 (or 9513) A-1090 Wien, AUSTRIA cmp.mpi.univie.ac.at ----------------------------------------------------------------- slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12