bug in str.startswith() and str.endswith()

Discussion in 'Python' started by Ethan Furman, May 27, 2011.

  1. Ethan Furman

    Ethan Furman Guest

    I've tried this in 2.5 - 3.2:

    --> 'this is a test'.startswith('this')
    True
    --> 'this is a test'.startswith('this', None, None)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: slice indices must be integers or None or have an __index__
    method

    The 3.2 docs say this:

    str.startswith(prefix[, start[, end]])
    Return True if string starts with the prefix, otherwise return False.
    prefix can also be a tuple of prefixes to look for. With optional start,
    test string beginning at that position. With optional end, stop
    comparing string at that position

    str.endswith(suffix[, start[, end]])
    Return True if the string ends with the specified suffix, otherwise
    return False. suffix can also be a tuple of suffixes to look for. With
    optional start, test beginning at that position. With optional end, stop
    comparing at that position.

    Any reason this is not a bug?

    ~Ethan~
    Ethan Furman, May 27, 2011
    #1
    1. Advertising

  2. Ethan Furman

    Mel Guest

    Ethan Furman wrote:

    > I've tried this in 2.5 - 3.2:
    >
    > --> 'this is a test'.startswith('this')
    > True
    > --> 'this is a test'.startswith('this', None, None)
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: slice indices must be integers or None or have an __index__
    > method
    >
    > The 3.2 docs say this:
    >
    > str.startswith(prefix[, start[, end]])
    > Return True if string starts with the prefix, otherwise return False.
    > prefix can also be a tuple of prefixes to look for. With optional start,
    > test string beginning at that position. With optional end, stop
    > comparing string at that position
    >
    > str.endswith(suffix[, start[, end]])
    > Return True if the string ends with the specified suffix, otherwise
    > return False. suffix can also be a tuple of suffixes to look for. With
    > optional start, test beginning at that position. With optional end, stop
    > comparing at that position.
    >
    > Any reason this is not a bug?


    It's a wart at the very least. The same thing happened in Python2 with
    range and xrange; there seemed no way to explicitly pass "default"
    arguments.

    Mel.
    Mel, May 27, 2011
    #2
    1. Advertising

  3. Ethan Furman

    Roy Smith Guest

    In article <>,
    Ethan Furman <> wrote:

    > --> 'this is a test'.startswith('this')
    > True
    > --> 'this is a test'.startswith('this', None, None)
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: slice indices must be integers or None or have an __index__
    > method

    [...]
    > Any reason this is not a bug?


    +1 for it being a bug.
    Roy Smith, May 27, 2011
    #3
  4. Roy Smith, 27.05.2011 03:13:
    > Ethan Furman wrote:
    >
    >> --> 'this is a test'.startswith('this')
    >> True
    >> --> 'this is a test'.startswith('this', None, None)
    >> Traceback (most recent call last):
    >> File "<stdin>", line 1, in<module>
    >> TypeError: slice indices must be integers or None or have an __index__
    >> method

    > [...]
    >> Any reason this is not a bug?

    >
    > +1 for it being a bug.


    Meaning that the right thing to do at this point is to file a bug report.

    Stefan
    Stefan Behnel, May 27, 2011
    #4
  5. Ethan Furman

    Roy Smith Guest

    In article <>,
    Stefan Behnel <> wrote:

    > Roy Smith, 27.05.2011 03:13:
    > > Ethan Furman wrote:
    > >
    > >> --> 'this is a test'.startswith('this')
    > >> True
    > >> --> 'this is a test'.startswith('this', None, None)
    > >> Traceback (most recent call last):
    > >> File "<stdin>", line 1, in<module>
    > >> TypeError: slice indices must be integers or None or have an __index__
    > >> method

    > > [...]
    > >> Any reason this is not a bug?

    > >
    > > +1 for it being a bug.

    >
    > Meaning that the right thing to do at this point is to file a bug report.


    And now we just need to figure out if it's a bug in the code or the
    documentation :)
    Roy Smith, May 27, 2011
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    17
    Views:
    1,860
    Chris Uppal
    Nov 16, 2005
  2. Roedy Green
    Replies:
    14
    Views:
    725
    Mickey Segal
    Jan 31, 2006
  3. Michele Simionato

    feature request: a better str.endswith

    Michele Simionato, Jul 18, 2003, in forum: Python
    Replies:
    24
    Views:
    776
    Peter Hansen
    Jan 9, 2004
  4. Brian Cole
    Replies:
    1
    Views:
    394
    Paul Rubin
    Jan 10, 2006
  5. metaperl
    Replies:
    5
    Views:
    293
    Lawrence D'Oliveiro
    Sep 29, 2006
Loading...

Share This Page