How to copy a class instance in python?

前端 未结 3 1571
遥遥无期
遥遥无期 2021-02-07 03:16

I would like to make a copy of a class instance in python. I tried copy.deepcopy but I get the error message:

RuntimeError: Only Variables cr

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 03:40

    Yes you can make a copy of class instance using deepcopy:

    from copy import deepcopy
    
    c = C(4,5,'r'=2)
    d = deepcopy(c)
    

    This creates the copy of class instance 'c' in 'd' .

提交回复
热议问题