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
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\
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.
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
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
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',&
[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']
>
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.