简体   繁体   中英

Why Python3.2 can't deepcopy(globals())?

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?

不,这不是因为deepcopy执行时会更改globals dict,但正如异常所示,它在处理过程中遇到了特殊的NotImplemented 内置常量 ,即NotImplementedType类型的元素,无法实例化并进行复制。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM