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

Terry Reedy tjreedy at home.com
Fri Feb 8 12:34:34 EST 2002


[posted and cc'd]
"Bruce Dykes" <bkd at graphnet.com> wrote
> What the heck am I doing wrong here?

Beats me.  Works fine here.  Copying your posted function (and filling
in rest) ...

>>> import string
>>>
>>> lines = [
...   'line1 header1 header2',
...   'line2 datum1  datum2']
>>>
>>> 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
...
>>> process_numbers(lines)
0 3 ['line1', 'header1', 'header2']
1 3 ['line2', 'datum1', 'datum2']

gives exactly the output you expected.  So you must have actually run
something else.

Moral: always post what you actually ran (cut to minimal size) and its
output (cut and paste), not what you think you did run, or a
description thereof.

Terry J. Reedy







More information about the Python-list mailing list