"Maximum recursion depth exceeded"...why?
Thomas Allen
thomasmallen at gmail.com
Tue Feb 17 21:19:55 EST 2009
On Feb 17, 9:08 pm, Christian Heimes <li... at cheimes.de> wrote:
> Thomas Allen wrote:
> > If you'd read the messages in this thread you'd understand why I'm not
> > using os.walk(): I'm not using it because I need my code to be aware
> > of the current recursion depth so that the correct number of "../" are
> > substituted in.
>
> I'm well aware of your messages and your requirements. However you
> didn't either read or understand what I was trying to tell you. You
> don't need to know the recursion depths in order to find the correct
> number of "../".
>
> base = os.path.normpath(base)
> baselevel = root.count(os.sep)
>
> for root, dirs, files in os.walk(base):
> level = root.count(os.sep) - baselevel
> offset = level * "../"
> ...
>
> See?
>
> Christian
Very clever (and now seemingly obvious)! That certainly is one way to
measure directory depth; I hadn't thought of counting the separator.
Sorry that I misunderstood what you meant there.
Thanks,
Thomas
More information about the Python-list
mailing list