from os.path import basename datafile = "abc/123.dat" name = basename(datafile) print(name) ''' 123.dat '''