How to get a substring with variable indices

Paul Rubin http
Mon Dec 18 08:30:07 EST 2006


ÁâÐÝØáÛÐÒ ÏÓÛÞ <stas at legche.net> writes:
> text[s:e] generates the following error:
>     TypeError: slice indices must be integers or None
> 
> How to be? :)

s and e both have to be integers or None.  Try printing them out just
before your slice to see if their values are reasonable.

    >>> s = 2
    >>> e = 4
    >>> "python"[s:e]
    'th'



More information about the Python-list mailing list