[Tutor] Stuck on Something

Britt Green britt_green@hotmail.com
Tue, 06 Mar 2001 23:13:10 -0800


>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.

Hmm, interesting. I have a copy of Core Python Programming by Wesley Chun 
right here, and it lists string.splitlines() as a string function. But when 
I check on the Python website, all I see is string.split(). Odd.


>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*)

Ok. The line x = string.split(dlist, '\n') will split a listing of the FTP 
directory into individual lines, instead of just one giant string. So 
instead of having:

drwxrwx---   2 restback privftp       512 Mar  6 21:23 technicolorkitchen
drwxrwx---   2 restback privftp       512 Mar  6 21:58 theclubhouse
drwxrwx---   2 restback privftp       512 Mar  6 21:07 thirdstreet
drwxrwx---   2 restback privftp       512 Feb 27 11:18 thyme

it looks more like ['drwxrwx--- 2 restback...', 'drwxrwx--- 2 restback...', 
'etc', 'etc]. I guess I should ask if I'm making the correct assumption 
here. Thats what the output seems to suggest.

Assuming that I'm not mistaken here, the next step is to have Python remove 
from each line the name of the directory. So in the above examples it needs 
to have 'theclubhouse', 'thirdstreet' and 'thyme' removed from the line.

This is where I'm getting a bit stuck. I can't seem to get this to be 
removed. I've tried a couple of different things but the most i can get it 
to return is a single letter.

Hopefully that wasn't too vague. Any suggestions?

Britt


--
It is pitch black. You are likely to be eaten by a grue.

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com