confusion regarding os.path.walk()

Steve Holden sholden at
Wed Feb 20 08:19:49 EST 2002

"Andrew Brown" <killspam at> wrote in message
news:Xns91BB770F47AD4andrewdarwinwarscom at
> rmunn at (Robin Munn) wrote in
> news:slrna75bg5.hg.rmunn at
> > assuming
> > burrows.html is the "real" file and Burrows.htm is the symlink you
> > want to create, then the command you really want to be running is:
> >
> > ln -s burrows.html ./wombats/habitat/Burrows.htm
> >
> > This will create the symlink Burrows.htm -> burrows.html in the
> > directory wombats/habitat. If you did:
> >
> > ln -s ./wombats/habitat/burrows.html ./wombats/habitat/Burrows.htm
> >
> > then what you would get would be: in the directory wombats/habitat,
> > there would be a symlink named Burrows.htm that tried to reference
> > wombats/habitat/wombats/habitat/burrows.html -- this is almost
> > certainly not what you wanted.
> >
> Yes. This is exactly the gotcha that got me. It's not at all obvious, and
> it's not really a python problem either. It seems to arise from the way
> that Unix makes symlinks: I had assumed that it first looks for the file
> to link to, and then makes the link file. But it turns out to be the
> other way around. So, though I had tried all sorts of path manipulations
> to ensure that the link was found relative to the file linked to, I never
> tried chopping the path of the target file, which would have solved my
> problem.
> Thanks for your help, and I hope this sometime helps a passing googler.
> Other people will surely fall into the same pit.

They surely will, and you've done a useful piece of learning (as well as
helping future Googlers). Next time, remind yourself: "There's a reason why
symbolic links are called symbolic"!

The path is, as you have discovered, generated by appending strings, not by
traversing the filestore tree.

Consulting, training, speaking:
Author, Python Web Programming:

"This is Python.  We don't care much about theory, except where it
intersects with useful practice."  Aahz Maruch on

More information about the Python-list mailing list