Request Help With Byte/String Problem

Wildman best_lay at yahoo.com
Tue Nov 29 23:01:51 EST 2016


On Tue, 29 Nov 2016 18:29:51 -0800, Paul Rubin wrote:

> Wildman <best_lay at yahoo.com> writes:
>>     names = array.array("B", '\0' * bytes)
>> TypeError: cannot use a str to initialize an array with typecode 'B'
> 
> In Python 2, str is a byte string and you can do that.  In Python 3,
> str is a unicode string, and if you want a byte string you have to
> specify that explicitly, like b'foo' instead of 'foo'.  I.e.
> 
>      names = array.array("B", b'\0' * bytes)
> 
> should work.

I really appreciate your reply.  Your suggestion fixed that
problem, however, a new error appeared.  I am doing some
research to try to figure it out but no luck so far.

Traceback (most recent call last):
  File "./ifaces.py", line 33, in <module>
    ifs = all_interfaces()
  File "./ifaces.py", line 21, in all_interfaces
    name = namestr[i:i+16].split('\0', 1)[0]
TypeError: Type str doesn't support the buffer API


-- 
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!



More information about the Python-list mailing list