RE Despair - help required

rafi rafi at
Thu Aug 25 16:13:31 CEST 2005

Yoav wrote:
> 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')
('c:/foo', 'bar')
 >>> os.path.splitext ('c:/foo/bar')
('c:/foo/bar', '')
 >>> os.path.splitext ('c:/foo/bar.txt')
('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?
>> </F>


	"Imagination is more important than knowledge."
	                            (Albert Einstein)

More information about the Python-list mailing list