[Python-bugs-list] [ python-Feature Requests-681533 ] Additional string stuff.

SourceForge.net noreply@sourceforge.net
Thu, 06 Feb 2003 00:14:20 -0800


Feature Requests item #681533, was opened at 2003-02-06 03:14
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=681533&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Nobody/Anonymous (nobody)
Summary: Additional string stuff.

Initial Comment:
In a lot of my programs that mess with strings, I end up 
somewhere making a variable "ascii" via 
(string.maketrans('', '')).  It's just a 256-character string 
comprising the ascii character set. 
 
I use it, oftentimes, simply to be able to turn the 'translate' 
method on strings into a 'delete' method -- if I want to, 
say, remove all the spaces in aString, I'd do 
(aString.translate(ascii, string.whitespace)). 
 
Certainly an ascii variable in the string module couldn't 
hurt, would fit in with ascii_letters, etc. and would at least 
standarize the name of the full ascii set sure to be 
present in many Python programs. 
 
A little further out there, but I think just as useful, would 
be a delete method on strings.  So "foo bar 
baz".delete(string.whitespace) would return "foobarbaz".  
It would be equivalent to "foo bar baz".translate(ascii, 
string.whitespace), or the wildly inefficient: 
 
def delete(s, deleteChars): 
    l = [] 
    for c in s: 
        if c not in deleteChars: 
            l.append(c) 
    return ''.join(l) 
 
Anyway, that's all I can think of.  Do with it what you will. 
 
Jeremy 

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

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