Steve Jorgensen wrote: > Currently, if I know that I want an array.array object with > itemsize of 4 there is no way to do that without first determining what the > item sizes are for 'i'/'I' and > 'l'/'L' on the current platform. Presumably, things could get > even more hairy with future platforms. > Below are some ideas for how to support explicit, platform-agnostic item size > specification. …
Other ideas: Allow supplying an integer `itemsize` value as the `typecode` with a positive value for unsigned or a negative value for signed. ``` a = array.array(-4) # Signed a = array.array(4) # Unsigned ``` Allow supplying a simple slice as the `typecode` defining the smallest rage of values that an item should be able to represent. The array function object would also support indexing to produce a curried `array` function with the given a slice as its first argument. When either the signed or unsigned item type of a given size could encompass the given range, then the unsigned type would be used. ``` # Signed short items initialized with [1, 2, 3] a = array.array(slice(-1, 200), Range(1, 4)) # or... a = array.array[-1:200](Range(1, 4)) # Unsigned 4-byte items (int (I) or long (L) depending on platform) a = array.array(slice(0, 0x90_00_00_00)) # or... a = array.array[0:0x90_00_00_00]() # or… a = array.array[0:0x70_00_00_00]() # Would fit into signed or unsigned. ``` _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/X3BSMNS5DLJUYND3SCWVCAAS5WMOUNEF/ Code of Conduct: http://python.org/psf/codeofconduct/