Reputation: 175
I have run these codes in python 3.2.2 IDLE:
from copy import deepcopy
deepcopy(globals())
And i get the error message:
Traceback (most recent call last):
File "H:\ \python\copy deepcopy.py", line 27, in <module>
deepcopy(globals())
File "D:\Program Files\Python32\lib\copy.py", line 147, in deepcopy
y = copier(x, memo)
File "D:\Program Files\Python32\lib\copy.py", line 236, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "D:\Program Files\Python32\lib\copy.py", line 174, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "D:\Program Files\Python32\lib\copy.py", line 290, in _reconstruct
state = deepcopy(state, memo)
File "D:\Program Files\Python32\lib\copy.py", line 147, in deepcopy
y = copier(x, memo)
File "D:\Program Files\Python32\lib\copy.py", line 236, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "D:\Program Files\Python32\lib\copy.py", line 174, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "D:\Program Files\Python32\lib\copy.py", line 285, in _reconstruct
y = callable(*args)
File "D:\Program Files\Python32\lib\copyreg.py", line 88, in __newobj__
return cls.__new__(cls, *args)
TypeError: object.__new__(NotImplementedType) is not safe, use NotImplementedType.__new__()
So I don't know why we can't do deepcopy() to globals()?
Because that the deepcopy() change the globals dict when it exec?
Upvotes: 1
Views: 422
Reputation: 1777
No this is not because deepcopy
change the globals dict when it executes, but as the exception shows it, during it's process, it encounter the special NotImplemented
built-in constant, an element of type NotImplementedType
which it can't instantiate and thus copy.
Upvotes: 3