copying generators error
Aahz
aahz at pythoncraft.com
Mon Mar 3 11:56:24 EST 2003
In article <mailman.1046640064.16956.python-list at python.org>,
Gerrit Holl <gerrit at nl.linux.org> wrote:
>
>when copying a listiterator, I get the following error:
>
>22:21:29:3:gerrit at stopcontact:~/cvs/pygame/examples$ python
>Python 2.3a2+ (#6, Mar 2 2003, 14:26:40)
>[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-110)] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
> 0 >>> import copy
> 1 >>> copy.copy(iter([]))
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.3/copy.py", line 95, in copy
> return _reconstruct(x, rv, 0)
> File "/usr/local/lib/python2.3/copy.py", line 336, in _reconstruct
> y = callable(*args)
> File "/usr/local/lib/python2.3/copy_reg.py", line 84, in __newobj__
> return cls.__new__(cls, *args)
>TypeError: object.__new__(listiterator) is not safe, use listiterator.__new__()
>
>Is this a bug?
Don't think so:
Python 2.2.2 (#1, Oct 17 2002, 12:22:01)
[GCC egcs-2.91.66 19990314 (egcs-1.1.2 release)] on netbsd1
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy
>>> f = open('x')
>>> copy.copy(f)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/pkg/python-2.2.2/lib/python2.2/copy.py", line 84, in copy
y = _reconstruct(x, reductor(), 0)
File "/pkg/python-2.2.2/lib/python2.2/copy_reg.py", line 57, in _reduce
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle file objects
You might argue that iterators should return a different error, but
stateful objects like files and iterators shouldn't be copied.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Register for PyCon now! http://www.python.org/pycon/reg.html
More information about the Python-list
mailing list