Author Chris.Barker
Recipients Chris.Barker, ChrisBarker, Gaurav Tatke, Jim.Jewett, docs@python, rhettinger, serhiy.storchaka
Date 2016-12-30.23:40:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CALGmxE+8mFWMFKOsHaCf_ok7K-uqR-Z8L0F-jqcC1XMepoPd7w@mail.gmail.com>
In-reply-to <1483129079.93.0.769410977765.issue28612@psf.upfronthosting.co.za>
Content
This all came out of a thread on python-ideas, starting here:

https://mail.python.org/pipermail/python-ideas/2016-October/043284.html

the thread kind of petered out, but it seems there was a kinda-sorta
consensus that we didn't need any new string methods, but rather same notes
in the docs on how to to use .translate() to remove "all but these" was in
order.

And the defaultdict method was proposed as the easiest / most pythonic.

As it happens, I did't live the fact hat defaultdict will build up a
big(ish) dict of Nones for no reason, and thus suggested a NoneDict option:

class NoneDict(dict):
    """
    Dictionary implementation that always returns None when a key is not in
the dict,
    rather than raising a KeyError
    """
    def __getitem__(self, key):
        try:
            val = dict.__getitem__(self, key)
        except KeyError:
            val = None
        return val

Though maybe that's a bit much for the docs.

However, in short:

either the defaultdict approach is siple and pythonic enough to be in teh
docs, or we SHOULD add something new to the string object.

(or maybe someone has another nifty pythonic way to do this with the stdlib
that's better than defaultdict?)

-CHB

On Fri, Dec 30, 2016 at 12:18 PM, Gaurav Tatke <report@bugs.python.org>
wrote:

>
> Gaurav Tatke added the comment:
>
> Should a user be suggested to use str.translate() for the use case where
> user only wants to keep certain characters and strip off everything else?
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue28612>
> _______________________________________
>

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov
History
Date User Action Args
2016-12-30 23:40:16Chris.Barkersetrecipients: + Chris.Barker, rhettinger, docs@python, Jim.Jewett, serhiy.storchaka, ChrisBarker, Gaurav Tatke
2016-12-30 23:40:16Chris.Barkerlinkissue28612 messages
2016-12-30 23:40:16Chris.Barkercreate