[NEWBIE] List issue aka: "Why doesn't this code work?"

Quinn Dunkan quinn at hurl.ugcs.caltech.edu
Sun Feb 10 17:12:57 EST 2002


On Fri, 8 Feb 2002 10:51:55 -0500, Bruce Dykes <bkd at graphnet.com> wrote:
>Okay, here's my function:
>
>def process_numbers(source_list):
>    for number in range(len(source_list)):
>        entry = string.split(string.strip(source_list[number]))
>        print number, len(entry), entry
>
>Now this function is doing *something*...source_list is a list of lines
>retrieved via ftp.retrlines(), and this should break each line into it's own
>list, and it looks like that's what's being printed out:
>
>['line1', 'header1', 'header2']
>['line2', 'datum1', 'datum2']
>
>Notice what's missing? I'm expecting to see:
>
>0 3 ['line1', 'header1', 'header2']
>1 3 ['line2', 'datum1', 'datum2']
>
>What the heck am I doing wrong here?

Forgetting to reload the module?

It works for me.

>>> process_numbers(['line1 header1 header2', 'line2 datum1 datum2'])
0 3 ['line1', 'header1', 'header2']
1 3 ['line2', 'datum1', 'datum2']





More information about the Python-list mailing list