[Python-ideas] Python Convert
Daniel Rode
dth4h95 at gmail.com
Fri Jul 12 04:01:57 CEST 2013
Since Python3, the python creators removed a lot of encodings from the
str.encode() method. They did it because they weren't sure how to implement
the feature in Python3. They wanted it to be better.
I have an idea, add a built in method called "convert".
Usage example:
convert(data, current_state, desired_state)
convert(data, from, to)
Real world examples:
dataBytes = b"hello"
dataUTF8_Str = "Ɠahhhh hi all ̮"
convert(dataUTF8_Str, encodings.UTF8, encodings.BYTES)
Returns: b'\xc6\x93ahhhh hi all \xcc\xae'
convert(dataBytes, encodings.BYTES, encodings.HEX)
Returns: b'c693616868686820686920616c6c20ccae'
convert(dataUTF8_Str, encodings.UTF8, encodings.ASCII)
Returns: TypeError: can't convert utf8 character "\u0193" to ascii
Some other encodings:
BASE64
UTF16
UTF32
BINARY
Maybe even INT?
Feel free to add suggestions!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130711/e3ac1ca5/attachment.html>
More information about the Python-ideas
mailing list