Request Help With Byte/String Problem
best_lay at yahoo.com
Sat Dec 3 13:00:59 EST 2016
On Fri, 02 Dec 2016 19:39:39 +0000, Grant Edwards wrote:
> On 2016-12-02, Wildman via Python-list <python-list at python.org> wrote:
>> On Fri, 02 Dec 2016 15:11:18 +0000, Grant Edwards wrote:
>>> I don't know what the "addr" array contains, but if addr is a byte
>>> string, then the "int()" call is not needed, in Pythong 3, a byte is
>>> already an integer:
>>> def format_ip(a):
>>> return '.'.join(str(b) for b in a)
>>> addr = b'\x12\x34\x56\x78'
>> It is a byte string just like your 'addr =' example and
>> the above code works perfectly.
> More importantly, you've now learned about generator comprehensions
> (aka generator expressions) and the string type's "join" method. ;)
I have seen the join method before but because of my lack
of experience it didn't occur to me to use it. I bet I
will remember it from now on. I stuck a few code examples
into my 'snips' directory.
Generator expressions are new to me. I have seen it's use
but I didn't understand what it was and what it was doing,
until now. Thanks again.
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!
More information about the Python-list