>> > Is there any consensus forming on whether bytes() instances are >> > mutable or not? >> >> Mutable! Phillip> So, how will it be different from: Phillip> from array import array Phillip> def bytes(*initializer): Phillip> return array('B',*initializer) That might well be a decent trial implementation, though it seems that if we allow strings as initializers we should also allow strings in assignment: >>> b = bytes("abc\xff") >>> b array('B', [97, 98, 99, 255]) >>> print buffer(b) abcÿ >>> b[3] = '\xfe' Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: an integer is required >>> b += "\xfe" Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: can only extend array with array (not "str") I must admit I'm having a bit of trouble getting past this point with a more traditional subclass (can array objects not be subclassed?) in part I think because I don't understand new-style classes very well. In particular, I couldn't find a description of __new__, and once I fumbled past that, I didn't seem to be able to override append() or extend(). Skip
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4