On Tue, Jun 22, 2010 at 08:24:28AM -0500, Michael Urman wrote: > On Tue, Jun 22, 2010 at 00:28, Stephen J. Turnbull <stephen at xemacs.org> wrote: > > Michael Urman writes: > > > > > It is somewhat troublesome that there doesn't appear to be an obvious > > > built-in idempotent-when-possible function that gives back the > > > provided bytes/str, > > > > If you want something idempotent, it's already the case that > > bytes(b'abc') => b'abc'. What might be desirable is to make > > bytes('abc') work and return b'abc', but only if 'abc' is pure ASCII > > (or maybe ISO 8859/1). > > By idempotent-when-possible, I mean to_bytes(str_or_bytes, encoding, > errors) that would pass an instance of bytes through, or encode an > instance of str. And of course a to_str that performs similarly, > passing str through and decoding bytes. While bytes(b'abc') will give > me b'abc', neither bytes('abc') nor bytes(b'abc', 'latin-1') get me > the b'abc' I want to see. > A month or so ago, I finally broke down and wrote a python2 library that had these functions in it (along with a bunch of other trivial boilerplate functions that I found myself writing over and over in different projects) https://fedorahosted.org/releases/k/i/kitchen/docs/api-text-converters.html#unicode-and-byte-str-conversion I suppose I could port this to python3 and we could see if it gains adoption as a thirdparty addon. I have been hesitating over doing that since I don't use python3 for everyday work and I have a vague feeling that 2to3 won't understand what that code needs to do. -Toshio -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20100622/d2ac6dea/attachment.pgp>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4