[Tutor] Finding bottom level directories, and command-line arguments

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Feb 8 01:43:58 CET 2006



On Wed, 8 Feb 2006, Simon Gerber wrote:

> I watch many different TV shows on my PC, as many of us do. But I am
> sick and tired of forgetting which episode I was up to. So, in a
> prodigious effort to avoid ever using, say, a pen, I am working on a
> script to take over some of my brain's memory handling. When complete, I
> will simply be able to type, for example, 'play family_guy' from the
> command line and it will automatically launch the next unwatched
> episode.


Hi Simon,

It might be interesting to write a function that takes an arbitrary
directory, and returns 'True' if that directory is a bottom-level
directory.  Can you write this function?

If so, then we can use it to solve the problem of getting all bottom-level
directories: we can recursively walk all directories from a root, and just
keep the ones that say 'True' to our helper function.  Does this make
sense?



> Second question - anyone have some good pointers/links about how to
> parse command line arguments effectively? I.e. perhaps build a
> dictionary of all options and their values, so I can deal with them
> appropriately?

There's a module that does this called 'optparse':

    http://www.python.org/doc/lib/module-optparse.html

Try reusing that first, because it's been fairly well exercised and tuned
to what people expect from an option parser.


If you have more questions, please feel free to ask.  Good luck!



More information about the Tutor mailing list