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.

Allow a non-str sequence with itemsize and signedness members to be given as 
the `typecode` value. 
`a = array.array((4, array.SIGNED))`

Allow a numeric `itemsize` value to be given as the first positional argument 
instead of a `typecode` string, and have an optional named argument for 
signedness, signed by default.
`a = array.array(4)  # Signed by default.`
`a = array.array(4, signedness=array.UNSIGNED)`

Allow the "@" and "=" prefixes (same as in `struct` format strings) in 
`typecode` strings. This is my least preferred because I won't always have the 
typecode or prefix value choices memorized, and looking them up is an extra 
step. Also, the appropriate size and signedness might be determined at runtime, 
so having to write additional code to map from size/signedness to a typecode is 
an unnecessary annoyance.
`a = array.array('=i')  # Signed integer of "standard" integer size.`
_______________________________________________
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/Y5S75LPSREFKIXJWMB66FVWDCCC546PH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to