mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
* 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
This commit is contained in:
parent
b3f7258f14
commit
d316607732
15 changed files with 127 additions and 35 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue