"Maximum recursion depth exceeded"...why?

Thomas Allen thomasmallen at gmail.com
Tue Feb 17 20:46:06 EST 2009


On Feb 17, 7:05 pm, Christian Heimes <li... at cheimes.de> wrote:
> Thomas Allen wrote:
> > I'm referring to the same code, but with a print:
>
> > for file in os.listdir(dir):
> >     if os.path.isdir(file):
> >         print "D", file
>
> > in place of the internal call to absToRel...and only one line prints
> > such a message. I mean, if I can't trust my OS or its Python
> > implementation (on a Windows box) to recognize a directory, I'm
> > wasting everyone's time here.
>
> You are under a wrong assumption. You think os.listdir() returns a list
> of absolute path elements. In fact it returns just a list of names. You
> have to os.path.join(dir, file) to get an absolute path.
>
> Anyway stop reinventing the wheel and use os.walk() as I already
> explained. You can easily spot the depth with "directory.count(os.sep)".
>  os.path.normpath() helps you to sanitize the path before counting the
> number of os.sep.
>
> Christian

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.

Also, somebody mentioned wget -R...did you mean wget -r? In any case,
I have all of these files locally already and am trying to replace
absolute paths with relative ones so that a colleague can present some
website content at a location with no internet.

Thomas



More information about the Python-list mailing list