[Python-ideas] More user-friendly version for string.translate()

Chris Barker chris.barker at noaa.gov
Mon Oct 24 16:54:58 EDT 2016


On Mon, Oct 24, 2016 at 1:30 PM, Mikhail V <mikhailwas at gmail.com> wrote:

> But how would you with current translate function drop all characters
> that are not in the table?


that is another question altogether, and one for a different list, actually.

I don't know a way to do "remove every character except these", but someone
I expect there is a way to do that efficiently with Python strings.

you could probably (ab)use the codecs module, though.

If there really is no way to do it, then you might have feature worth
pursuing, but be prepared with use-cases!

The only use-case I've had for that sort of this is when I want only ASCII
-- but I can uses the ascii codec for that :-)

This for example
> is needed for filtering out all non-standard characters from paths, etc.
>

You'd usually want to replace those with something, rather than remove them
entirely, yes?

-CHB



> So in other words, there should be an option to control this behavior.
> Probably I am missing something here, but I didn't find such solution
> for translate() and that is main point of proposal actually.
> It is all the same as translate() but with this extension it can cover
> much more usage cases.
>
>
> Mikhail
>



-- 

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 at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161024/7a38fbad/attachment.html>


More information about the Python-ideas mailing list