deep-copy

How to create a copy of a python function

How to create a copy of a python function Question: Is there a possibility to create real copies of python functions? The most obvious choice was http://docs.python.org/2/library/copy.html but there I read: It does “copy” functions and classes (shallow and deeply), by returning the original object unchanged; I need a real copy, because I might change …

Total answers: 1

What is the runtime complexity of Python's deepcopy()?

What is the runtime complexity of Python's deepcopy()? Question: I’m trying to improve the speed of an algorithm and, after looking at which operations are being called, I’m having difficulty pinning down exactly what’s slowing things up. I’m wondering if Python’s deepcopy() could possibly be the culprit or if I should look a little further …

Total answers: 4

How can I make a deepcopy of a function in Python?

How can I make a deepcopy of a function in Python? Question: I would like to make a deepcopy of a function in Python. The copy module is not helpful, according to the documentation, which says: This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any …

Total answers: 9

Copying nested lists in Python

Copying nested lists in Python Question: I want to copy a 2D list, so that if I modify one list, the other is not modified. For a one-dimensional list, I just do this: a = [1, 2] b = a[:] And now if I modify b, a is not modified. But this doesn’t work for …

Total answers: 4

copy.deepcopy vs pickle

copy.deepcopy vs pickle Question: I have a tree structure of widgets e.g. collection contains models and model contains widgets. I want to copy whole collection, copy.deepcopy is faster in comparison to ‘pickle and de-pickle’ing the object but cPickle as being written in C is much faster, so Why shouldn’t I(we) always be using cPickle instead …

Total answers: 5

Python dictionary deepcopy

Python dictionary deepcopy Question: I was wondering in how does exactly deepcopy work in the following context: from copy import deepcopy def copyExample: self.myDict = {} firstPosition = “First” firstPositionContent = [“first”, “primero”] secondPosition = “Second” secondPositionContent = [“second”] self.myDict[firstPosition] = firstPositionContent self.myDict[secondPosition] = secondPositionContent return deepcopy(self.myDict) def addExample(self): copy = self.copyExample() copy[“Second”].add(“segundo”) Does it …

Total answers: 2