[issue47052] allow string as sep in _Py_strhex_impl ( bytearray.hex() )

2022-03-17 Thread Dennis Sweeney

Dennis Sweeney  added the comment:

In particular, it's one ascii character:

>>> b'abracadabra'.hex('')
ValueError: sep must be ASCII.

I wouldn't be completely opposed to allowing longer strings, but since there 
are easy enough ways to do it already, put me at a -0. We can see if anyone 
else is in favor.

--
components: +Interpreter Core -IO
nosy: +gregory.p.smith
versions: +Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47052] allow string as sep in _Py_strhex_impl ( bytearray.hex() )

2022-03-17 Thread arne123


arne123  added the comment:

Well, I think there are many ways to solve this in python (e.g. I used 
iteration before, wasn't aware of the sep. at all), but when there is already a 
separator, why limiting it to one character?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47052] allow string as sep in _Py_strhex_impl ( bytearray.hex() )

2022-03-17 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Would there be substantial benefit of a new feature over using the existing 
feature and then calling str.replace()?

>>> b = b'abracadabra'
>>> "0x" + b.hex(":").replace(":", ", 0x")
'0x61, 0x62, 0x72, 0x61, 0x63, 0x61, 0x64, 0x61, 0x62, 0x72, 0x61'

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47052] allow string as sep in _Py_strhex_impl ( bytearray.hex() )

2022-03-17 Thread arne123


New submission from arne123 :

I use Python to support some C development.
Often I need to convert bytearrays to C like convention:
0x12, 0x34

It would be very convenient for this use case if the separator could be a 
string (like ", 0x") instead of just a single character.

--
components: IO
messages: 415447
nosy: arne123
priority: normal
severity: normal
status: open
title: allow string as sep in _Py_strhex_impl ( bytearray.hex() )
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com