[Tutor] tree problem

Joel Goldstick joel.goldstick at gmail.com
Sun Sep 12 15:08:18 CEST 2010


On Sun, Sep 12, 2010 at 7:54 AM, Lie Ryan <lie.1296 at gmail.com> wrote:

> On 09/12/10 21:15, Roelof Wobben wrote:
> >
> >
> > Hello,
> >
> > I have this problem.
> >
> > Write a program named litter.py that creates an empty file named
> trash.txt in each subdirectory of a directory tree given the root of the
> tree as an argument (or the current directory as a default).
>
> By default, Python has a recursion limit of 1000 deep; that is, your
> function is calling itself 1000 times without returning.
>
> In this case, the only reason why you hit the recursion limit is if you
> have a directory which is 1000 deep (quite unlikely, Windows has a
> directory depth limit much lower than that).
>
> Or your function somehow never returns, in a typical recursive function,
> it's usually because you have problem in the precondition.
>
> You really have two problems here:

1. You need to know how to write an empty file with the name litter.py.  You
should probably write a function to see if you can do that.  That's pretty
easy

2. You need to traverse a tree.  I see you are using os module.  You should
try help(os) while in your python shell to learn what methods are
available.  Traversing a tree is also sometimes called 'walking'

good luck


-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100912/04bc4960/attachment-0001.html>


More information about the Tutor mailing list