Possible Duplicate:
Python, extract file name from path, no matter what the os/path format
I have a string as:
filename = "C:\\mydata\\yourdata\\Finaldata.txt"
>>> filename
'C:\\mydata\\yourdata\\Finaldata.txt'
i wish to split and pick the last element also when i don't know where is the path. I wrote these lines code
from os import path
path.splitext(filename)[0].split("\\")[len(path.splitext(filename)[0].split("\\"))-1]
'Finaldata'
but i am looking if there is an elegant way to do this. thanks in advance for any help Gianni