Python version 2.3.3 under WindowsXP Home Edition
The standard library "copy" does not work with the
standard library "array".
import copy
import array
x = array.array('c', 'abcdef')
y = copy.copy(x)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/copy.py", line 95, in copy
return _reconstruct(x, rv, 0)
File "/usr/lib/python2.3/copy.py", line 338, in
_reconstruct
y = callable(*args)
File "/usr/lib/python2.3/copy_reg.py", line 92, in
__newobj__
return cls.__new__(cls, *args)
TypeError: array() takes at least 1 argument (0 given)
The same thing happens for copy.deepcopy.
Judging from the TypeError details, it appears that
copy.copy assumes a new object of the same type as its
input argument can be created with no arguments, but
array.array requires at least one argument (describing
the type of items in the array).
array.array should have a custom method added to make
it work smoothly with copy.copy.
Documentation for copy.copy should be clearer about the
requirements on the type of its input argument.
|