[Patches] [ python-Patches-675864 ] patch for new func. string.findall

SourceForge.net noreply@sourceforge.net
Mon, 14 Jul 2003 00:40:54 -0700


Patches item #675864, was opened at 2003-01-27 21:00
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=675864&group_id=5470

Category: None
Group: None
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Hunter Peress (hfastedge)
Assigned to: Nobody/Anonymous (nobody)
Summary: patch for new func. string.findall

Initial Comment:
this finds all indices of a substring in a string
returning in list form. Its not in pydoc2.3.

This "patch" contains unittests.

#!/usr/bin/python
import string

def findall(sub,s):
    if s =='' or sub =='':
        return []

    ret=[]
    findval=0
    pos=0
    while findval != -1:
        findval = s.find(sub,pos)
        if findval != -1:
            ret.append(findval)
            pos = findval + len(sub)
    return ret

if __name__ == '__main__':
    units = [
    'asdsad','l',
    'l','asdlsds',
    'l','lsdlsds',
    'l','lsdsds',
    'l','sdsds',
    'l','sdsdsl',
    'l','lsdsdsl',
    'l','lsdlsdsl',

    'l','l',
    'l','ll',
    'l','lll',

    'lo','llollol',
    'lo','llollolo',

    '','',
    '','asdasd',
    'asdsad',''
    ]
    for i in range(0,len(units),2):
        sub,s = units[i],units[i+1]
        print "'%s' in '%s':"%(sub,s)
        print findall(sub,s)
        print "-"*30

    print 'done'


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-07-14 02:40

Message:
Logged In: YES 
user_id=80475

This function (aspiring method) does not have a strong 
enough use case to warrant fattening the API for str, 
unicode, UserString, etc.

Am closing this one.  But do keep submitting ideas to 
improve the language.

----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-05-28 19:59

Message:
Logged In: YES 
user_id=357491

The string module is deprecated so adding anything to the module is a big 
no-no.  If you still want to see this functionality it will require being added to 
the string type.

I am also changing this to a patch since it has working code (albeit as-is it 
would be rejected).

----------------------------------------------------------------------

Comment By: Hunter Peress (hfastedge)
Date: 2003-01-31 04:31

Message:
Logged In: YES 
user_id=479934

Theres now a indented version of that which was pasted above
that is attached to this bug.

----------------------------------------------------------------------

Comment By: Hunter Peress (hfastedge)
Date: 2003-01-27 21:01

Message:
Logged In: YES 
user_id=479934

This might be done as an iterator as well, as re.findall
also is complemented by an re.finditer.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=675864&group_id=5470