>>> path = '/etc/passwd' >>> import os >>> os.path.dirname(path) '/etc' >>> os.path.basename(path) 'passwd'