Re: split a directory string into a list

2005-02-28 Thread Josef Meile
The most obvious case where it wouldn't work would be for a UNC path name. Using the string split method gives two empty strings: os.path.normpath(r'\\machine\share').split(os.path.sep) ['', '', 'machine', 'share'] whereas the splitpath function I proposed gives you: splitpath(r'\\machine\shar

Re: split a directory string into a list

2005-02-26 Thread Duncan Booth
Josef Meile wrote: > "This should work ***reasonably*** reliably on Windows and Unix". Are > there any cases when it does not work? The most obvious case where it wouldn't work would be for a UNC path name. Using the string split method gives two empty strings: >>> os.path.normpath(r'\\machine\

Re: split a directory string into a list

2005-02-25 Thread Josef Meile
Hi Duncan, This should work reasonably reliably on Windows and Unix: somestring = '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' os.path.normpath(somestring).split(os.path.sep) ['', 'foo', 'bar', 'beer', 'sex', 'cigarettes', 'drugs', 'alcohol'] However a better solution is probably to call os.path.

Re: split a directory string into a list

2005-02-25 Thread Duncan Booth
Michael Maibaum wrote: > On 25 Feb 2005, at 14:09, Harper, Gina wrote: > >> I would start with something like this: >> somestring = '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' >> somelist = somestring.split('/') >> print somelist > > However - this will not work on Windows. It'd work on all th

Re: split a directory string into a list

2005-02-25 Thread Michael Maibaum
On 25 Feb 2005, at 14:09, Harper, Gina wrote: I would start with something like this: somestring = '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' somelist = somestring.split('/') print somelist However - this will not work on Windows. It'd work on all the OS I usually use though ;) Michael -- htt

RE: split a directory string into a list

2005-02-25 Thread Harper, Gina
ECTED] Sent: Friday, February 25, 2005 8:36 AM To: python-list@python.org Subject: split a directory string into a list QUESTION: How do I split a directory string into a list in Python, eg. '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' becomes ['foo','bar',&

Re: split a directory string into a list

2005-02-25 Thread Kent Johnson
[EMAIL PROTECTED] wrote: QUESTION: How do I split a directory string into a list in Python, eg. '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' becomes ['foo','bar','beer','sex','cigarettes','drugs','alcohol'] >

split a directory string into a list

2005-02-25 Thread porterboy76
QUESTION: How do I split a directory string into a list in Python, eg. '/foo/bar/beer/sex/cigarettes/drugs/alcohol/' becomes ['foo','bar','beer','sex','cigarettes','drugs','alcohol'] I was looking at the os.path.