rosedb0 at gmail.com
Mon Oct 16 21:22:06 CEST 2006
rdhar... at gmail.com wrote:
> I have thousands of files that look something like this:
> I need to extract the string between the *last* underscore and the
> So based on the files above, I want returned:
> My plan was to use .split or .find but I can't figure out how locate
> only the last underscore in the filename.
> Anyone have any ideas?
Try splitting the string on "." and using rfind to find the last
instance of "_".
myStr = "wisconsin_state.txt"
pieces = myStr.split(".")
substr = pieces[pieces.rfind("_") + 1:]
More information about the Python-list