Wildman via Python-list <python-list@python.org> writes: > On Tue, 29 Nov 2016 18:29:51 -0800, Paul Rubin wrote: > >> Wildman <best_...@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
It's the same issue and same fix. Use b'\0' instead of '\0' for the argument to split(). There'll be a couple more issues with the printing but they should be easy enough. -- https://mail.python.org/mailman/listinfo/python-list