[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']

>>> '/foo/bar/beer/sex/cigarettes/drugs/alcohol/'.strip('/').split('/') ['foo', 'bar', 'beer', 'sex', 'cigarettes', 'drugs', 'alcohol']

Kent

I was looking at the os.path.split command, but it only seems to separate the filename from the path (or am I just using it wrong?). I don't want to do it manually if I can help it, as there will have to be exceptions for the cases where there is (not) a trailing (leading) slash, or escape sequences involving /. Is there a built in command for this?

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to