<div dir="ltr">my thought on this:<div><br></div><div>If you need translate() you probably can write the code to parse a text file, and then you can use whatever format you want.</div><div><br></div><div>This seems a very special case to build into the stdlib.</div><div><br></div><div>-CHB</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 24, 2016 at 10:39 AM, Mikhail V <span dir="ltr"><<a href="mailto:mikhailwas@gmail.com" target="_blank">mikhailwas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all,<br>
<br>
I would be happy to see a somewhat more general and user friendly<br>
version of string.translate function.<br>
It could work this way:<br>
string.newtranslate(file_with_<wbr>table, Drop=True, Dec=True)<br>
<br>
So the parameters:<br>
<br>
1. "file_with_table" : a text file with table in following format:<br>
<br>
#[In]    [Out]<br>
<br>
97    {65}<br>
98    {66}<br>
99    {67}<br>
100    {}<br>
...<br>
110    {110}<br>
<br>
<br>
Notes:<br>
All values are decimal or hex (to switch between parsing format use<br>
Dec parameter)<br>
As it turned out from my last discussion, majority prefers hex notation,<br>
so I am not in mainstream with my decimal notation here, but both<br>
should be supported.<br>
Empty [Out] value {} means that the character will be deleted.<br>
<br>
2. "Drop = True" this will set the default behavior for those values<br>
which are NOT in the table.<br>
<br>
For Drop = True: all values not defined in table set to [out] = {},<br>
and be deleted.<br>
<br>
For Drop=False: all values not defined in table set [out] = [in], so<br>
those remain as is.<br>
<br>
3. Dec= True : parsing format Decimal/hex. I use decimal everywhere.<br>
<br>
<br>
Further thoughts: for 8-bit strings this should be simple to implement<br>
I think. For 16-bit of course<br>
there is issue of memory usage for lookup tables, but the gurus could<br>
probably optimise it.<br>
E.g. at the parsing stage it is not necessary to build the lookup<br>
table  for whole 16-bit range of course,<br>
but take only values till the largest ordinal present in the table file.<br>
<br>
About the format of table file: I suppose many users would want also<br>
to define characters directly, I am not sure<br>
if it is really needed, but if so, additional brackets or escape char<br>
could be used, like this for example:<br>
<br>
a    {A}<br>
\98    {\66}<br>
\99    {\67}<br>
<br>
but as said I don't like very much the idea and would be OK for me to<br>
use numeric values only.<br>
<br>
So approximately I see it.<br>
Feel free to share thoughts or criticise.<br>
<br>
<br>
Mikhail<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div>