[Tutor] How to create array of variants?

John Fouhy john at fouhy.net
Tue Jul 8 05:56:03 CEST 2008


On 08/07/2008, Kelie <kf9150 at gmail.com> wrote:
>  I'm trying to translate the following VB code into Python and not sure how to
>  create an array of variants.

I'm not sure what an array of variants in VB is -- perhaps an array
that can contain objects of any type?

>  Python code
>  import array

You may not need to use the array module -- the array module is
specifically for arrays of numerics in situations where performance
matters.  In general in Python, you get array-like behaviour using
lists.  Lists can hold objects of any type.

For example:

>>> myList = [100, 'Test application']
>>> myList[0]
100
>>> myList[1]
'Test application'

I recommend reading a python tutorial if this is new to you.

-- 
John.


More information about the Tutor mailing list