How to walk up parent directories?
Snorri H
a.a.ovtchinnikov at gmail.com
Mon May 4 08:26:23 EDT 2009
On May 4, 5:04 am, Matthew Wilson <m... at tplus1.com> wrote:
> Is there already a tool in the standard library to let me walk up from a
> subdirectory to the top of my file system?
Never seen such a standard tool, yet it can be implemented in a way
like this
def walkup(path):
aux = path.rsplit('/')
while aux != ['']:
yield reduce(lambda x,y:x+'/'+y,aux)
aux.pop()
yield '/'
Maybe this is not the best way to ascend directories, but it seems to
work.
More information about the Python-list
mailing list