Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66782
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'problem:': 0.07; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'def': 0.12; 'hint:': 0.16; 'line.split()': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'repr(line)': 0.16; 'index': 0.16; 'wrote:': 0.18; 'starts': 0.20; 'saying': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; '12th': 0.24; 'header:X-Complaints-To:1': 0.27; 'skip:( 20': 0.30; 'lines': 0.31; 'subject:numbers': 0.31; 'subject:from': 0.34; 'add': 0.35; 'list': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'email addr:gmail.com': 0.63; 'name': 0.63; 'subject:The': 0.64; 'more': 0.64; 'scores': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: The sum of numbers in a line from a file |
| Date | Thu, 20 Feb 2014 19:59:31 +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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd871e.dip0.t-ipconnect.de |
| User-Agent | KNode/4.7.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7203.1392922774.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1392922774 news.xs4all.nl 2867 [2001:888:2000:d::a6]:44784 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:66782 |
Show key headers only | View raw
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