[Python-ideas] Change the array declaration syntax.

Nick Coghlan ncoghlan at gmail.com
Tue Feb 8 15:07:58 CET 2011


On Tue, Feb 8, 2011 at 9:52 PM, Arthur <azrael.zila at gmail.com> wrote:
> Thus, the variable "var" is a list, not a tuple,  even if it
> is declared with with a tuple instead of a list:
>>>> var = array('i',(1,2,3))
>>>> var
> array('i', [1, 2, 3])

Note that an array is its own beast - it just happens to use list
notation in its repr, as the square brackets contrast better with the
parentheses used for the function call syntax.

Regardless, if you want a quick and easy way to create arrays of
particular types, just define your own constructor function:

>>> from array import array
>>> def iarray(*elements):
...     return array('i', elements)
...
>>> x = iarray(1, 2, 3)
>>> x
array('i', [1, 2, 3])

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list