More nits to pick with arrays ...

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Thu, 4 Nov 1993 12:32:22 -0500

Note that:
type(array('f')) == type(array('l')) == <type 'array'>

>>> from array import array
>>> f = array( 'f', range( 1, 10 ))
>>> l = array( 'l', range( 1, 10 ))
>>> h = array( 'h', range( 1, 10 ))
>>> h
array('h', [1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> h[:3]
array('h', [1, 2, 3])
>>> h[-3:]
array('h', [7, 8, 9])
>>> h[:3] + h[-3:] #1
array('h', [1, 2, 3, 1, 2, 3]) #2
>>> f[:3] + l[-3:] #3
Stack backtrace (innermost last):
File "<stdin>", line 1
TypeError: illegal argument type for built-in operation
>>>

Note that the statement marked #1 makes sense, but the answer
( #2 ) is incorrect.
Expression #3 doesn't really make any sense when you understand
the rationale of array types, but considering the relation at
the top of the page, a PROGRAM ( as opposed to a reasonable
person ) would have every right to expect it to work and NOT
generate that exception. ( Let's assume that the program has
tested type(arg1) == type(arg2) and that arg1 and arg2 both
have the __getslice__ attribute, etc. )

What are the pro's and con's of making:
type(array('f')) == <type 'array-f'>
type(array('l')) == <type 'array-l'>
... etc.

- Steve M.