A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/089684.html below:

IndexError: string index out of range

IndexError: string index out of range IndexError: string index out of rangeAlex Martelli aleaxit at yahoo.com
Thu Apr 12 04:14:36 EDT 2001
"michael" <mhyoung at valdosta.edu> wrote in message
news:mailman.987034096.12363.python-list at python.org...
    [snip]
>   if (buf[0] == EXCLUDE):

This assumes 0 is in-range as an index: it will not be
if buf is an EMPTY (0-length) string.

> learning purposes. This program works fine until it gets to the last
> line in the testfile and I get this error.

Right, because after the last line an empty string is returned.

> Can someone please tell me what I'm doing wrong? I've looked all over
> the net and in several books for a solution.

For example, just change this previously-quoted test to
    if buf.startswith(EXCLUDE):

THIS will work even when buf is the 0-length string.


Alex




More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4