From d316607732aa70361d5793f6b301b70fab7ca367 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 24 May 1993 14:16:22 +0000 Subject: * ftplib.py: added abort() command (sends oob data). * Several modules: change "class C(): ..." to "class C: ...". * flp.py: support for frozen forms. * Added string.find() which is like index but returns -1 if not found --- Lib/string.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'Lib/string.py') diff --git a/Lib/string.py b/Lib/string.py index e5dc1946bc..8c7d102b46 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -93,7 +93,7 @@ def joinfields(words, sep): res = res + (sep + w) return res[len(sep):] -# Find substring +# Find substring, raise exception if not found index_error = 'substring not found in string.index' def index(s, sub, *args): if args: @@ -107,7 +107,14 @@ def index(s, sub, *args): while i < m: if sub == s[i:i+n]: return i i = i+1 - raise index_error, (s, sub) + raise index_error, (s, sub) + args + +# Find substring, return -1 if not found +def find(*args): + try: + return apply(index, args) + except index_error: + return -1 # Convert string to integer atoi_error = 'non-numeric argument to string.atoi' -- cgit v1.2.1