Snorri H wrote:

> On May 4, 5:04 am, Matthew Wilson <m...@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.

It's not working for windows. And using reduce to create a path instead of 

os.sep.join(aux)

seems to be showing off mad functional coding skillz than anything else...

Diez
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to