You can use os.path.basename here instead of the rsplit.