Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'tuple': 0.09; 'wrote:': 0.15; 'pathname': 0.16; 'windows:': 0.16; 'cc:addr:python-list': 0.16; 'pm,': 0.16; '>>>': 0.16; 'subject:list': 0.16; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'received:209.85.220': 0.25; 'skip:[ 10': 0.26; 'van': 0.27; 'thu,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.30; 'components,': 0.30; 'skip:\xa0 30': 0.32; 'list': 0.32; '8bit%:3': 0.35; 'function.': 0.35; 'subject: ?': 0.35; 'skip:o 20': 0.36; 'but': 0.37; 'using': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; "there's": 0.39; 'received:209': 0.40; "i'd": 0.40; 'skip:r 20': 0.40; 'subject:skip:o 10': 0.84 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=KWzi51MfeYQPeUepsUeoHT/4/D/bNEqPCzddhrH2KBA=; b=beTK9qlbeQqR/oh2xIxUeGGuh+MTm4XWzAwBE6B2Yn79UrDcwTJbGsLo6QcSjj78Jc nXzwQkg6LZwWTFHVdKKhFI96QG+2OFnxbzinqmheREaNMYHI4RqMT5+NO0/xIiqIpGgy PxtpYzlybG6EXrjKq/Z4v4nIcqs3ZaGzZMj1A= 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:31:43 -0600 Subject: Re: list comprehension to do os.path.split_all ? To: Emile van Sebille 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311888735 news.xs4all.nl 23945 [2001:888:2000:d::a6]:49013 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10483 On Thu, Jul 28, 2011 at 3:15 PM, Emile van Sebille wrote: > On 7/28/2011 1:18 PM gry said... >> >> [python 2.7] I have a (linux) pathname that I'd like to split >> completely into a list of components, e.g.: >> =A0 =A0'/home/gyoung/hacks/pathhack/foo.py' =A0--> =A0 ['home', 'gyoung'= , >> 'hacks', 'pathhack', 'foo.py'] >> >> os.path.split gives me a tuple of dirname,basename, but there's no >> os.path.split_all function. >> > > Why not just split? > > '/home/gyoung/hacks/pathhack/foo.py'.split(os.sep) Using os.sep doesn't make it cross-platform. On Windows: >>> os.path.split(r'C:\windows') ('C:\\', 'windows') >>> os.path.split(r'C:/windows') ('C:/', 'windows') >>> r'C:\windows'.split(os.sep) ['C:', 'windows'] >>> r'C:/windows'.split(os.sep) ['C:/windows']