String Manipulation
Fredrik Lundh
fredrik at pythonware.com
Tue Jul 15 18:51:55 EDT 2003
Irmen de Jong wrote:
> While is is perfectly acceptable, you might want to consider another
> solution if it is *path names* you are manipulating:
>
> >>> import os
> >>> os.path.split("aaa/bbb/ccc/dd")
> ('aaa/bbb/ccc', 'dd')
> >>> os.path.split("aaa/bbb/ccc/dd")[1]
> 'dd'
or:
>>> os.path.basename("aaa/bbb/ccc/dd")
'dd'
(use os.path.dirname to get the directory part)
</F>
More information about the Python-list
mailing list