summaryrefslogtreecommitdiffstats
path: root/Lib/stringold.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-05-24 14:16:22 (GMT)
committerGuido van Rossum <guido@python.org>1993-05-24 14:16:22 (GMT)
commitd316607732aa70361d5793f6b301b70fab7ca367 (patch)
treed87376c3075042ebffdbf8bb13416f8055a5fd13 /Lib/stringold.py
parentb3f7258f14cb2f3e52236a4087ed82541a173e7b (diff)
downloadcpython-d316607732aa70361d5793f6b301b70fab7ca367.zip
cpython-d316607732aa70361d5793f6b301b70fab7ca367.tar.gz
cpython-d316607732aa70361d5793f6b301b70fab7ca367.tar.bz2
* 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
Diffstat (limited to 'Lib/stringold.py')
-rw-r--r--Lib/stringold.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/stringold.py b/Lib/stringold.py
index e5dc194..8c7d102 100644
--- a/Lib/stringold.py
+++ b/Lib/stringold.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'