Python copy.py() Examples
The following are code examples for showing how to use copy.py(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.
def __deepcopy__(self, memo=None): ''' Helper method to copy.py's deepcopy function. Call it from there. memo=None is the default as specified in copy.py Problem: if an attribute is defined with an understscore (_priority) but is also made available through a property (e.g. priority) using dir(self) results in the copy happening twice. Thus, __dict__.keys() is used. >>> from copy import deepcopy >>> from music21 import note, duration >>> n = note.Note('A') >>> n.offset = 1.0 #duration.Duration("quarter") >>> n.groups.append("flute") >>> n.groups ['flute'] >>> idN = n.id >>> idN > 10000 # pointer True >>> b = deepcopy(n) >>> b.offset = 2.0 #duration.Duration("half") >>> n is b False >>> b.id != n.id True >>> n.accidental = "-" >>> b.name 'A' >>> n.offset 1.0 >>> b.offset 2.0 >>> n.groups = "bassoon" >>> ("flute" in n.groups, "flute" in b.groups) (False, True) ''' #environLocal.printDebug(['calling Music21Object.__deepcopy__', self]) new = self._deepcopySubclassable(memo) # must do this after copying new.purgeOrphans() #environLocal.printDebug([self, 'end deepcopy', 'self._activeSite', self._activeSite]) return new