Re: stripping unwanted chars from string

2006-05-04 Thread Alex Martelli
Edward Elliott <[EMAIL PROTECTED]> wrote: > I'm looking for the "best" way to strip a large set of chars from a filename > string (my definition of best usually means succinct and readable). I > only want to allow alphanumeric chars, dashes, and periods. This is what I > would write in Perl (bl

Re: stripping unwanted chars from string

2006-05-04 Thread John Machin
On 4/05/2006 4:30 PM, Edward Elliott wrote: > Bryan wrote: >> >>> keepchars = set(string.letters + string.digits + '-.') > > Now that looks a lot better. Just don't forget the underscore. :) > *Looks* better than the monkey business. Perhaps I should point out to those of the studio audience

Re: stripping unwanted chars from string

2006-05-04 Thread bruno at modulix
Edward Elliott wrote: > Bryan wrote: > >> >>> keepchars = set(string.letters + string.digits + '-.') > > > Now that looks a lot better. Just don't forget the underscore. :) > You may also want to have a look at string.translate() and string.maketrans() -- bruno desthuilliers python -c "print

Re: stripping unwanted chars from string

2006-05-03 Thread Edward Elliott
Bryan wrote: > >>> keepchars = set(string.letters + string.digits + '-.') Now that looks a lot better. Just don't forget the underscore. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: stripping unwanted chars from string

2006-05-03 Thread Edward Elliott
John Machin wrote: > [expletives deleted] and it was wrong anyway (according to your > requirements); > using \w would keep '_' which is *NOT* alphanumeric. Actually the perl is correct, the explanation was the faulty part. When in doubt, trust the code. Plus I explicitly allowed _ further down,

Re: stripping unwanted chars from string

2006-05-03 Thread Bryan
> >>> keepchars = set(alphabet + alphabet.upper() + '1234567890-.') or >>> keepchars = set(string.letters + string.digits + '-.') bryan -- http://mail.python.org/mailman/listinfo/python-list

Re: stripping unwanted chars from string

2006-05-03 Thread John Machin
On 4/05/2006 1:36 PM, Edward Elliott wrote: > I'm looking for the "best" way to strip a large set of chars from a filename > string (my definition of best usually means succinct and readable). I > only want to allow alphanumeric chars, dashes, and periods. This is what I > would write in (b

stripping unwanted chars from string

2006-05-03 Thread Edward Elliott
I'm looking for the "best" way to strip a large set of chars from a filename string (my definition of best usually means succinct and readable). I only want to allow alphanumeric chars, dashes, and periods. This is what I would write in Perl (bless me father, for I have sinned...): $filename =~