Re: Parsing a path to components

2008-06-10 Thread Scott David Daniels
eliben wrote: ... a prety good try ... def parse_path(path): """...""" By the way, the comment is fine. I am going for brevity here. lst = [] while 1: head, tail = os.path.split(path) if tail == '': if head != '': lst.insert(0, head) break

Re: Parsing a path to components

2008-06-09 Thread Duncan Booth
"Mark Tolonen" <[EMAIL PROTECTED]> wrote: >> Can you recommend a generic way to achieve this ? >> Eli > import os from os.path import normpath,abspath x=r'\foo\\bar/baz//spam.py' normpath(x) > '\\foo\\bar\\baz\\spam.py' normpath(abspath(x)) > 'C:\\foo\\bar\\baz\\spam.py'

Re: Parsing a path to components

2008-06-07 Thread Mark Tolonen
"eliben" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Jun 7, 10:15 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: On Fri, 06 Jun 2008 23:57:03 -0700, s0suk3 wrote: > You can just split the path on `os.sep', which contains the path > separator of the platform on which

Re: Parsing a path to components

2008-06-07 Thread Marc 'BlackJack' Rintsch
On Sat, 07 Jun 2008 02:15:07 -0700, s0suk3 wrote: > On Jun 7, 3:15 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Fri, 06 Jun 2008 23:57:03 -0700, s0suk3 wrote: >> > You can just split the path on `os.sep', which contains the path >> > separator of the platform on which Python is ru

Re: Parsing a path to components

2008-06-07 Thread s0suk3
On Jun 7, 3:15 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Fri, 06 Jun 2008 23:57:03 -0700, s0suk3 wrote: > > You can just split the path on `os.sep', which contains the path > > separator of the platform on which Python is running: > > > components = pathString.split(os.sep) > > W

Re: Parsing a path to components

2008-06-07 Thread eliben
On Jun 7, 10:15 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Fri, 06 Jun 2008 23:57:03 -0700, s0suk3 wrote: > > You can just split the path on `os.sep', which contains the path > > separator of the platform on which Python is running: > > > components = pathString.split(os.sep) > >

Re: Parsing a path to components

2008-06-07 Thread Marc 'BlackJack' Rintsch
On Fri, 06 Jun 2008 23:57:03 -0700, s0suk3 wrote: > You can just split the path on `os.sep', which contains the path > separator of the platform on which Python is running: > > components = pathString.split(os.sep) Won't work for platforms with more than one path separator and if a separator is

Re: Parsing a path to components

2008-06-07 Thread s0suk3
On Jun 7, 12:55 am, eliben <[EMAIL PROTECTED]> wrote: > Hello, > > os.path.split returns the head and tail of a path, but what if I want > to have all the components ? I could not find a portable way to do > this in the standard library, so I've concocted the following > function. It uses os.path.s

Parsing a path to components

2008-06-06 Thread eliben
Hello, os.path.split returns the head and tail of a path, but what if I want to have all the components ? I could not find a portable way to do this in the standard library, so I've concocted the following function. It uses os.path.split to be portable, at the expense of efficiency. -