[Python-ideas] Change the array declaration syntax.

Arthur azrael.zila at gmail.com
Tue Feb 8 15:34:44 CET 2011


I thought about how to do but did not analyze the feasibility, sorry about
that. It could be after the symbol']'and ')'. So would:

>>> var1 = [1, 2, 3]i # a singletype int list, as a current array
>>> var2 = ('1', '2', '3')i # a singletype int tuple, as a current
>>> array, but immutable

Até mais!
Ass.: Arthur Julião
------------------------------------------------------------------------------------------------
"Quero que a estrada venha sempre até você e que o vento esteja sempre a seu
favor, quero que haja sempre uma cerveja em sua mão e que esteja ao seu lado
seu grande amor." (Tempo Ruim - A Arte do Insulto - Matanza)


2011/2/8 Nick Coghlan <ncoghlan at gmail.com>

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110208/f494c384/attachment.html>


More information about the Python-ideas mailing list