This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: str.index() exception message not consistent
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: blunck2, inyeol, rhettinger
Priority: normal Keywords:

Created on 2003-01-03 23:20 by inyeol, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Messages (3)
msg13864 - (view) Author: Inyeol Lee (inyeol) Date: 2003-01-03 23:20
$ python
Python 2.3a1 (#1, Jan  2 2003, 22:36:29) 
[GCC 2.95.3 20010315 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for
more information.
>>> 'a'.index('b')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: substring not found in string.index
>>> 'a'.rindex('b')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: substring not found in string.rindex
>>> u'a'.index('b')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: substring not found
>>> 

str.index()/str.rindex() exception message contains
"in string.(r)index", but
unicode.index()/unicode.rindex()
doesn't.

For me, unicode message is more clear, and it is
consistent with other string methods which raises
exception, for example;

>>> 'a'.split('')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: empty separator
>>> 

2.2.2 has the same issues.

Inyeol Lee
msg13865 - (view) Author: Christopher Blunck (blunck2) Date: 2003-01-08 05:29
Logged In: YES 
user_id=531881

see patch 664192
msg13866 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-01-15 05:39
Logged In: YES 
user_id=80475

Fixed.
See /Objects/stringobject.c 2.204.
Thanks for the bugreport.
History
Date User Action Args
2022-04-10 16:06:06adminsetgithub: 37712
2003-01-03 23:20:59inyeolcreate