[Tutor] Write array to Status text

Karl Pflästerer sigurd at 12move.de
Fri Nov 14 16:03:36 EST 2003


On 14 Nov 2003, Vicki Stanfield <- vicki at thepenguin.org wrote:

> I also have an array created like this:

> while i < 10:
>     array[i]=value
>     i = i +1

Is that an array or a list?  If you did nothing special it is a list.
What is value?  Do all entries have the same value?

> I would like to write the values in the array to the status bar. I tried:

>                 StatusText=errorarray[0:4]
>                 self.frame.SetStatusText(StatusText)

> TypeError: String or Unicode type required
> So, how does one convert the values of an array into a string for this
> purpose?

Let's say your array is a list.  So the slice (your [0:4]) returns a
list with the first 4 items (index 0 upto 3) of the sliced list.  So you
must find a way to convert your list to a string.  You can use the
`join' method of strings.

>>> l = ['a', 'b', 'c']
>>> ''.join(l)
'abc'
>>> 

If your array would really be an array you could use the `tostring'
method of arrays.

>>> import array
>>> arr = array.array('c', "I am an array of characters")
>>> arr[0:4] 
array('c', 'I am')
>>> arr[0:4].tostring()
'I am'
>>> 


   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list