String Manipulation
Inyeol Lee
inyeol.lee at siimage.com
Tue Jul 15 18:06:03 EDT 2003
On Tue, Jul 15, 2003 at 01:58:09PM -0700, Cousin Stanley wrote:
> | I need a piece of code that takes a string like this
> | string1 = "aaa/bbb/ccc/dd" and extracts a string containting
> | the character after the last "/"
> |
> | So for this example the result would be "dd"
> | ...
>
> lamar_air ...
>
> Here is one way ...
>
>
> >>> str_in = 'aaa/bbb/ccc/dd'
> >>>
> >>> list_in = str_in.split( '/' )
> >>>
> >>> last_element = list_in[ -1 ]
> >>>
> >>> print last_element
> dd
> >>>
>
>
> --
> Cousin Stanley
> Human Being
> Phoenix, Arizona
>
In Unix,
>>> os.path.basename("aaa/bbb/ccc")
'ccc'
Inyeol
More information about the Python-list
mailing list