How do I match the last occurence of a character?

Blake Winton bwinton at
Thu Jun 10 06:09:02 CEST 1999

On Wed, 09 Jun 1999, Steve Halliburton <shallib at> wrote:
>Why not just use the os module:
>>>> import os
>>>> name = 'news/breakingnews/981001b.html'
>>>> base = os.path.split(name)[0]
>>>> base
>>>> file = os.basename(name)
>>>> file

Would that work on NT, where the path separator is "/", but the
separator for the strings he wants to split is "\"?  Does it put the
drive in [0], and then the directory in [1]?  Unfortunately, I left my
NT box at the office, so I can't check and tell you.  And how would that
handle a full URL (i.e. "")?  What
about the Mac, where the separator is ":"?  Couldn't you have a basename
of "http", and a filename of "//"?  For
that matter, how does that handle something like "home/bwinton/"?  I'm
pretty sure my code can deal with both in a reasonable way, but I have
no idea what the os.path.split code would do, or what it would do on
different machines.


P.S. Sorry about mailing this to you as well as replying in the group...
     I didn't realize that you were posting as well, and perhaps it's a
     point worth sharing with the group.

One Will.  One Dream.  One Truth.  One Destiny.  One Love.

More information about the Python-list mailing list