[Tutor] Write array to Status text

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Nov 18 15:29:08 EST 2003



On Tue, 18 Nov 2003, Stanfield, Vicki {D167~Indianapolis} wrote:

> I ended up using a list, but I still think my info was better suited to
> an array. I had trouble getting the array right in my app, so I switched
> back to a list and finally got the StatusText thing to work. I did this:
>
> --------------------
> errorarray=[0] *5
> <SNIP>
> StatusText=""
> <SNIP part where count gets set>
> while returnedval != EOT:
> 	output=port.read()
> 	returnedval= hex(ord(output))
> 	if count == 1:
>          errorarray[byte]=returnedval
>          byte = byte +1
>
> StatusText=StatusText.join(str(errorarray[0:4]))
> self.frame.SetStatusText(StatusText)


Hi Vicki,


Ah, ok, I see now!  The returnedval's are hexadecimal strings!  Then the
code can be simplified to:


###
errorarray = []

<SNIP some setup code>

while returnedval != EOT:
    output = port.read()
    returnedval = hex(ord(output))
    if count == 1:
        errorarray.append(returnedval)

StatusText = ''.join(errorarray[0:4])
self.frame.SetStatusText(StatusText)
###


StatusText can be formatted in different ways; the code above will just
glue them end-to-end, and that might be hard to read.  Another way to do
it is to just say:

    StatusText = str(errorarray)

which should also show those values, separated by commas.


Glad to see the code is working for you now.  Talk to you later!




More information about the Tutor mailing list