from _testbuffer import objview from array import array def showmem(m): for attr in ['obj', 'nbytes', 'readonly', 'itemsize', 'format', 'ndim', 'shape', 'strides', 'suboffsets', "c_contiguous", "f_contiguous", "contiguous",]: print("%s = %r" % (attr, getattr(m, attr))) print("tobytes() -> %r" % m.tobytes()) if m.format == 'B': print("tolist() -> %r" % m.tolist()) print() t = ( b'abc', b'def', b'ghi', ) m = objview((t, t)) showmem(m) """ format = 'B' itemsize = 1 nbytes = 9 ndim = 2 readonly = True shape = (3, 3) strides = (8, 1) suboffsets = (48, -1) tobytes() -> b'abcdefghi' tolist() -> [[97, 98, 99], [100, 101, 102], [103, 104, 105]] """ tt = (t, t) m = objview(tt) showmem(m) """ format = 'B' itemsize = 1 nbytes = 18 ndim = 3 readonly = True shape = (2, 3, 3) strides = (8, 8, 1) suboffsets = (40, 48, -1) tobytes() -> b'abcdefghiabcdefghi' tolist() -> [[[97, 98, 99], [100, 101, 102], [103, 104, 105]], [[97, 98, 99], [100, 101, 102], [103, 104, 105]]] """ t = ( array('B', b'abc'), array('B', b'def'), array('B', b'ghi'), ) m = objview(t) showmem(m) """ format = 'B' itemsize = 1 nbytes = 9 ndim = 3 readonly = False shape = (3, 1, 3) strides = (8, 8, 1) suboffsets = (40, 0, -1) tobytes() -> b'abcdefghi' tolist() -> [[[97, 98, 99]], [[100, 101, 102]], [[103, 104, 105]]] """ tt = (t, t) m = objview(tt) showmem(m) """ format = 'B' itemsize = 1 nbytes = 18 ndim = 4 readonly = False shape = (2, 3, 1, 3) strides = (8, 8, 8, 1) suboffsets = (40, 40, 0, -1) tobytes() -> b'abcdefghiabcdefghi' tolist() ->-> [[[[97, 98, 99]], [[100, 101, 102]], [[103, 104, 105]]], [[[97, 98, 99]], [[100, 101, 102]], [[103, 104, 105]]]] """