New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bytes.tohex method #47782
Comments
I haven't been able to find a way to encode a bytes object in I recommend adding a bytes.tohex() method (in the same vein as the I've attached a patch which adds this method to the bytes and bytearray Style note: The bytesobject.c and bytearrayobject.c files are all over Commit log: Added "tohex" method to bytes and bytearray objects. Also added |
I recommend to use binascii.hexlify; this works in all Python version I'm -1 for this patch. |
Ah, see I did not know about this! Thanks for pointing it out.
Would it hurt to have the tohex method of the bytes object to perform Also why have a bytes.fromhex method when you could use binascii.unhexlify? (If it's better from a code standpoint, you could replace the code I |
Hmm. There are probably many modules that you haven't used yet.
So what? The desire to convert bytes into hex strings is infrequent Using functions is more extensible. If you wanted to produce base-85
There has been endless debates on this (or, something similar to this),
IMO, yes, it would. It complicates the code, and draws the focus away
That's highly debatable.
Good point. In any case, this is my opion; feel free to discuss this on python-dev. Very clearly it is too late to add this for 3.0 now. |
You did the 3.1 thing again! We can accept a new feature like this
Snap :) Well, I didn't know about the community's preference for functions over I think the biggest problem I have is the existence of fromhex. It's Also I think a lot of people (like me, in my relative inexperience) are |
Not without explicit approval by the release manager, no (or by BDFL The point of the betas is that *only* bugs get fixed, and *no* new |
Except, when we look at the context. This is bytes class Do we require an opposite in the bytes class method? Where will we use it?
No, it is not going away. str.encode('hex') is available to users when they |
>>> 'hello'.encode('hex')
LookupError: unknown encoding: hex This is deliberate, I'm pretty sure. encode/decode are for converting I'm just saying it should have something equally accessible to replace it. |
This is why we will get transform() and untransform() in 3.1. |
Oh, where's the information on those? (A brief search of the peps and bug tracker shows nothing). |
At the moment, mails on python-dev are the only source of information :) Look here: |
OK thanks. Well I still can't really see what transform/untransform are about. Is |
They are meant to replace encode/decode for those 2.x codecs that didn't |
So I assumed. In that case, why is there a "fromhex"? (Was that put in there before Anyway, assuming we go to 3.1 and add transform/untransform, I suppose |
Looks like transform/untransform went nowhere? |
This should be closed unless someone can provide a good reason for keeping it open. |
Closing as no response to msg110681. |
The 'add transform/untransform' issue seems to be bpo-7475. Note that there was in fact supposed to be a 'hex' method: http://mail.python.org/pipermail/python-dev/2009-September/091628.html Matt, if you'd like to raise this question again on python-dev, maybe your patch could be used to add it, in which case we could reopen this issue. Or we can wait for transform/untransform and just ignore the existence of fromhex :) |
See bpo-9951 for a patch adding bytes.hex |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: