Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66782
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: The sum of numbers in a line from a file |
| Date | 2014-02-20 19:59 +0100 |
| Organization | None |
| References | <882091da-a499-477e-8f50-c5bdde7cdfec@googlegroups.com> <le5bhe$461$1@reader1.panix.com> <9036049f-7d08-4de7-83f8-61e5fa2c2d2f@googlegroups.com> <mailman.7201.1392921172.18130.python-list@python.org> <5dacc2f1-811e-4c30-9873-2f7573a7bb76@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7203.1392922774.18130.python-list@python.org> (permalink) |
kjakupak@gmail.com wrote:
> Error comes up saying "IndexError: list index out of range."
OK, then the 12th line starts with a whitespace char. Add more print
statements to see the problem:
> scores = stu_scores()
print scores
> for line in scores:
print repr(line)
> fields = line.split()
> name = fields[0]
> print (fields)
Hint:
> def stu_scores():
> lines = []
> with open("file.txt") as f:
> lines.extend(f.readlines())
> return ("".join(lines[11:]))
Why did you "".join the lines?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
The sum of numbers in a line from a file kxjakkk <kjakupak@gmail.com> - 2014-02-20 08:22 -0800
Re: The sum of numbers in a line from a file John Gordon <gordon@panix.com> - 2014-02-20 16:46 +0000
Re: The sum of numbers in a line from a file kjakupak@gmail.com - 2014-02-20 10:16 -0800
Re: The sum of numbers in a line from a file Joel Goldstick <joel.goldstick@gmail.com> - 2014-02-20 13:32 -0500
Re: The sum of numbers in a line from a file kjakupak@gmail.com - 2014-02-20 10:37 -0800
Re: The sum of numbers in a line from a file Peter Otten <__peter__@web.de> - 2014-02-20 19:59 +0100
Re: The sum of numbers in a line from a file Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2014-02-20 19:56 +0100
Re: The sum of numbers in a line from a file MRAB <python@mrabarnett.plus.com> - 2014-02-20 19:17 +0000
Re:The sum of numbers in a line from a file Dave Angel <davea@davea.name> - 2014-02-20 11:54 -0500
Re: The sum of numbers in a line from a file Travis Griggs <travisgriggs@gmail.com> - 2014-02-20 14:35 -0800
Re: The sum of numbers in a line from a file Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-02-21 09:16 +0100
Re: The sum of numbers in a line from a file sffjunkie@gmail.com - 2014-02-24 03:48 -0800
Re: The sum of numbers in a line from a file sffjunkie@gmail.com - 2014-02-24 04:02 -0800
csiph-web