Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.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.068 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'think,': 0.05; 'manipulate': 0.09; 'manipulation': 0.09; 'skip:[ 30': 0.09; 'wrote:': 0.15; 'already.': 0.16; 'bieber': 0.16; 'mean,': 0.16; 'message-id:@web.de': 0.16; 'suggested.': 0.16; 'subject:list': 0.16; 'part,': 0.19; 'stick': 0.19; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'wonder': 0.23; 'handles': 0.25; 'string': 0.26; 'function': 0.26; 'lee': 0.28; "skip:' 30": 0.29; 'fixed': 0.29; 'carl': 0.30; 'from:addr:web.de': 0.30; 'list': 0.32; 'break': 0.33; 'to:addr:python-list': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'subject: ?': 0.35; "isn't": 0.35; 'open': 0.37; 'user': 0.38; 'subject:: ': 0.38; 'something': 0.38; 'should': 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'where': 0.40; 'your': 0.60; 'here.': 0.66; 'yourself': 0.68; 'enters': 0.73; 'received:172.20': 0.73; 'care': 0.73; 'dennis': 0.77; 'no?': 0.84; 'received:172.20.4': 0.84; 'received:172.20.4.166': 0.84; 'received:smtp05.web.de': 0.84; 'sender:addr:web.de': 0.84; 'subject:skip:o 10': 0.84 Date: Fri, 29 Jul 2011 22:22:54 +0200 From: Alexander Kapps User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11 MIME-Version: 1.0 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> In-Reply-To: <879a920c-d06a-4413-9566-6c9f0b737235@glegroupsg2000goo.googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: alex.kapps@web.de X-Sender: Alex.Kapps@web.de X-Provags-ID: V01U2FsdGVkX1/zQ7ztznvqVYLc2IdYrlVzZnEqGCx843aCAHSD dktfz7qUoDc0OhblT+ishBelftggEz/zt1BiLbadTYkR9OLN4e 5ROJchLgo= 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311971002 news.xs4all.nl 23950 [2001:888:2000:d::a6]:48151 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10541 On 29.07.2011 21:30, Carl Banks wrote: > It's not even fullproof on Unix. > > '/home//h1122/bin///ghi/'.split('/') > > ['','home','','bin','','','ghi',''] > > The whole point of the os.path functions are to take care of whatever oddities there are in the path system. When you use string manipulation to manipulate paths, you bypass all of that and leave yourself open to those oddities, and then you find your applications break when a user enters a doubled slash. > > So stick to os.path. > > > Carl Banks This would also be fixed with normpath() as Dennis Lee Bieber suggested. And my solution with list comprehensions handles this too. Still, there might be other path oddities which would break here. I think, that something like a split_all() function should be available in the stdlib, no? Actually, it isn't the first time, where I wonder why os.path.split() doesn't do this already. I mean, str.split() doesn't only split on the first part, right?