How do I match the last occurence of a character?

Blake Winton bwinton at tor.dhs.org
Thu Jun 10 06:09:02 CEST 1999


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

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. "http://tor.dhs.org/~bwinton/index.html")?  What
about the Mac, where the separator is ":"?  Couldn't you have a basename
of "http", and a filename of "//tor.dhs.org/~bwinton/index.html"?  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.

Later,
Blake.

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