[Tutor] What's the error (program) [use lists in favor of arrays]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Wed Nov 6 13:02:01 2002


Hi Alex,

Ok, let's take a look at your program... or at least the first few lines.
*grin*



> import array
[ some text cut]
> siteswap = array.array('B',[a,b,c])

The 'array' module has a specialized purpose: it's meant to store
collections of very primitive objects (numbers, strings) in a way that
guarantees how they're being stored in memory.  But this is a behavior
that you probably don't need to use at the moment.

Your array above is telling Python that you only want to store 'unsigned
characters' in your collection, but that's highly restrictive, since the
numbers in the collection can only range between 0 and 255!  So the binary
size restriction that we're placing on each array element may not be
helpful.


In many cases, a plain Python list is easier to work with:

###
siteswap = [a, b, c]
##

Are you coming from a language that uses arrays?  If so, try out Python
lists: you may find them very versatile and unrestrictive.


I have to go at the moment, but I'll try taking a look at the rest of your
program when I have more time.  Good luck to you!