[Tutor] Stuck on Something (fwd)

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Tue, 6 Mar 2001 21:45:18 -0800 (PST)


On Tue, 6 Mar 2001, Daniel Yoo wrote:

> Basically, this code goes into each of the three directories and
> returns, as a string, the list of directories in each folder. It kind
> of looks like this:
> 
> drwxrwx---   2 restback privftp       512 Feb  9 21:20 vivo
> drwxrwx---   2 restback privftp       512 Mar  6 21:09 voltaire
> drwxrwx---   2 restback privftp       512 Mar  6 21:10 vong
> drwxrwx---   2 restback privftp       512 Mar  6 21:07 watusi
> drwxrwx---   2 restback privftp       512 Mar  6 21:57 wildfire
> drwxrwx---   2 restback privftp       512 Mar  6 21:35 zinfandel


> So what I need to do with this chunk is to tell my program that vivo,
> voltaire, vong, etc are all directories it needs to enter. The way I
> thought I'd do this is to use the string.splitlines() command to split
> up folderContents into a list. Then I run into the problem of trying
> to split up each of the elements in the list. Its proving to be more
> difficult than I thought.

This looks reasonable.  However, I did a quick check on my system, but I
couldn't find string.splitlines().  Do you mean:

    string.split(some_large_string, '\n')

instead?  This should break your string into lists of lines.


Also, if you have a sequence, it's fairly easy to get the last element in
that sequence, by using negative indexing:

###
    l = [0, 1, 2, 3, 4, 5]
    print l[-1]
###

so it shouldn't be too hard to grab the directory names out of the list of
lines.  Can you show us where you're getting stuck?  We can help with
that.  (Getting unstuck, that is.  *grin*)

Double check the documentation for string, just to see what sort of stuff
you can use for your problem:

    http://python.org/doc/current/lib/module-string.html

Good luck!