RE Despair - help required
rafi at free.fr
Thu Aug 25 16:13:31 CEST 2005
> Don't think it will do much good. I need to get them from a file and
> extract the last folder in the path. For example:
> if I get "c:\dos\util"
> I want to extract the string "\util"
like frederik says (I use '/' as I am using Unix):
>>> import os
>>> os.path.split ('c:/foo/bar')
>>> os.path.splitext ('c:/foo/bar')
>>> os.path.splitext ('c:/foo/bar.txt')
or if you are really reluctant:
>>> 'c:\\foo\\bar'.split ('\\')
['c:', 'foo', 'bar']
>>> 'c:\\foo\\bar'.split ('\\') [-1]
> Fredrik Lundh wrote:
>> instead of struggling with weird REs, why not use Python's standard
>> filename manipulation library instead?
"Imagination is more important than knowledge."
More information about the Python-list