• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(10991)  |  Call(9558)  |  Derive(0)  |  Import(1433)
Deep copy operation on arbitrary Python objects.

See the module's __doc__ string for more info.

        def deepcopy(x, memo=None, _nil=[]):
    """Deep copy operation on arbitrary Python objects.

    See the module's __doc__ string for more info.
    """

    if memo is None:
        memo = {}

    d = id(x)
    y = memo.get(d, _nil)
    if y is not _nil:
        return y

    cls = type(x)

    copier = _deepcopy_dispatch.get(cls)
    if copier:
        y = copier(x, memo)
    else:
        try:
            issc = issubclass(cls, type)
        except TypeError: # cls is not a class (old Boost; see SF #502085)
            issc = 0
        if issc:
            y = _deepcopy_atomic(x, memo)
        else:
            copier = getattr(x, "__deepcopy__", None)
            if copier:
                y = copier(memo)
            else:
                reductor = dispatch_table.get(cls)
                if reductor:
                    rv = reductor(x)
                else:
                    reductor = getattr(x, "__reduce_ex__", None)
                    if reductor:
                        rv = reductor(2)
                    else:
                        reductor = getattr(x, "__reduce__", None)
                        if reductor:
                            rv = reductor()
                        else:
                            raise Error(
                                "un(deep)copyable object of type %s" % cls)
                y = _reconstruct(x, rv, 1, memo)

    memo[d] = y
    _keep_alive(x, memo) # Make sure x lives at least as long as d
    return y
        


src/e/c/ecell-HEAD/ecell4/trunk/doc/sample/ga/ga.py   ecell(Download)
 
		# validate resume file.
		aParameterMap = {}
		copy.deepcopy( Individual.theParameterMap, aParameterMap )
 
		aKeyDict = copy.deepcopy( Individual.theParameterMap )
 
			# -----------------------------------------------------
			# save elite individual
			# -----------------------------------------------------
			self.theEliteIndividual = copy.deepcopy( self.theIndividualList[0] )
			self.theEliteImprovedFlag = True
 
 
				# ---------------------
				# save elite individual
				# ---------------------
				self.theEliteIndividual = copy.deepcopy( self.theIndividualList[0] )
				self.theEliteImprovedFlag = True
 
				# ---------------------
			# -----------------------------------------------------
			else:
				self.theIndividualList[len(self.theIndividualList)-1] = \
				                           copy.deepcopy( self.theEliteIndividual )
				self.theEliteImprovedFlag = False
 
 
		anIndex = 0
		for aCopyNumber in aCopyNumberList:
			for aDummy in xrange(0,aCopyNumber):
				anIndividualListBuffer.append( copy.deepcopy(self.theIndividualList[anIndex]) )
			anIndex += 1
 
		# replace individual list
				for aFullID in aParentList[aK].getGenoType().keys():
					aCk[aFullID] = aX[aK][aFullID] + aC[aK][aFullID] 
 
				aChild = copy.deepcopy( self.theIndividualList[0] )
				aChild.setGenoType( aCk )
				aChild.setEvaluatedValue( None )
				aChildrenList.append( aChild )

src/e/c/ecell-HEAD/ecell3/trunk/doc/samples/ga/ga.py   ecell(Download)
 
        # validate resume file.
        aParameterMap = {}
        copy.deepcopy( Individual.theParameterMap, aParameterMap )
 
        aKeyDict = copy.deepcopy( Individual.theParameterMap )
 
            # -----------------------------------------------------
            # save elite individual
            # -----------------------------------------------------
            self.theEliteIndividual = copy.deepcopy( self.theIndividualList[0] )
            self.theEliteImprovedFlag = True
 
 
                # ---------------------
                # save elite individual
                # ---------------------
                self.theEliteIndividual = copy.deepcopy( self.theIndividualList[0] )
                self.theEliteImprovedFlag = True
 
                # ---------------------
            # -----------------------------------------------------
            else:
                self.theIndividualList[len(self.theIndividualList)-1] = \
                                           copy.deepcopy( self.theEliteIndividual )
                self.theEliteImprovedFlag = False
 
 
        anIndex = 0
        for aCopyNumber in aCopyNumberList:
            for aDummy in xrange(0,aCopyNumber):
                anIndividualListBuffer.append( copy.deepcopy(self.theIndividualList[anIndex]) )
            anIndex += 1
 
        # replace individual list
                for aFullID in aParentList[aK].getGenoType().keys():
                    aCk[aFullID] = aX[aK][aFullID] + aC[aK][aFullID] 
 
                aChild = copy.deepcopy( self.theIndividualList[0] )
                aChild.setGenoType( aCk )
                aChild.setEvaluatedValue( None )
                aChildrenList.append( aChild )

src/l/a/Langtangen-HEAD/src/py/examples/copytypes.py   Langtangen(Download)
a = A(-99)
b_assign  = a
b_shallow = copy.copy(a)
b_deep    = copy.deepcopy(a)
a.x = 9  # alter attribute in a
print 'a.x=%s, b_assign.x=%s, b_shallow.x=%s, b_deep.x=%s' %\
      (a.x, b_assign.x, b_shallow.x, b_deep.x)
 
a = A([-2,3])
b_assign  = a
b_shallow = copy.copy(a)
b_deep    = copy.deepcopy(a)
a = [4,3,5,['some string',2], A(-9)]
b_assign  = a
b_shallow = copy.copy(a)
b_deep    = copy.deepcopy(a)
b_slice   = a[0:5]
a[3] = 999; a[4].x = -6
print 'b_assign=%s\nb_shallow=%s\nb_deep=%s\nb_slice=%s' % \
      (b_assign, b_shallow, b_deep, b_slice)
 
# dictionaries behave similarly:
a = {'key1' : -99, 'key2' : ('str', 8, A(-9))}
b_assign  = a
b_shallow = copy.copy(a)
b_deep    = copy.deepcopy(a)

src/v/i/vizstack-HEAD/trunk/share/samples/display_setup/two-gpus-four-screens.py   vizstack(Download)
 
import vsapi
from pprint import pprint
from copy import deepcopy # deepcopy is python function we'll use to copy GPUs
import os
 
# Connect to the SSM
# Screen 0 drives a LP2065 monitor at default resolution, from port 0 of GPU0
scr0 = vsapi.Screen(0)
scr0.setFBProperty('position',[0,0])
gpu0_0 = deepcopy(gpu0) # Make a copy of the GPU so that we can assign display devices
gpu0_0.setScanout(port_index=0, display_device=ddName)
scr0.setGPU(gpu0_0)
srv.addScreen(scr0)
 
# Screen 1 drives a LP2065 monitor at default resolution, from port 1 of GPU0
scr1 = vsapi.Screen(1)
scr1.setFBProperty('position',[modeWidth,0])
gpu0_1 = deepcopy(gpu0)
# Screen 2 drives a LP2065 monitor at default resolution, from port 0 of GPU1
scr2 = vsapi.Screen(2)
scr2.setFBProperty('position',[0,modeHeight])
gpu1_0 = deepcopy(gpu1)
gpu1_0.setScanout(port_index=0, display_device=ddName)
scr2.setGPU(gpu1_0)
srv.addScreen(scr2)
 
# Screen 3 drives a LP2065 monitor at default resolution, from port 1 of GPU1
scr3 = vsapi.Screen(3)
scr3.setFBProperty('position',[modeWidth,modeHeight])
gpu1_1 = deepcopy(gpu1)

src/v/i/vizstack-HEAD/share/samples/display_setup/two-gpus-four-screens.py   vizstack(Download)
 
import vsapi
from pprint import pprint
from copy import deepcopy # deepcopy is python function we'll use to copy GPUs
import os
 
# Connect to the SSM
# Screen 0 drives a LP2065 monitor at default resolution, from port 0 of GPU0
scr0 = vsapi.Screen(0)
scr0.setFBProperty('position',[0,0])
gpu0_0 = deepcopy(gpu0) # Make a copy of the GPU so that we can assign display devices
gpu0_0.setScanout(port_index=0, display_device=ddName)
scr0.setGPU(gpu0_0)
srv.addScreen(scr0)
 
# Screen 1 drives a LP2065 monitor at default resolution, from port 1 of GPU0
scr1 = vsapi.Screen(1)
scr1.setFBProperty('position',[modeWidth,0])
gpu0_1 = deepcopy(gpu0)
# Screen 2 drives a LP2065 monitor at default resolution, from port 0 of GPU1
scr2 = vsapi.Screen(2)
scr2.setFBProperty('position',[0,modeHeight])
gpu1_0 = deepcopy(gpu1)
gpu1_0.setScanout(port_index=0, display_device=ddName)
scr2.setGPU(gpu1_0)
srv.addScreen(scr2)
 
# Screen 3 drives a LP2065 monitor at default resolution, from port 1 of GPU1
scr3 = vsapi.Screen(3)
scr3.setFBProperty('position',[modeWidth,modeHeight])
gpu1_1 = deepcopy(gpu1)

src/p/y/pypdflib-HEAD/samples/wiki2pdf/pyquery/pyquery.py   pypdflib(Download)
from cssselectpatch import selector_to_xpath
from lxml import etree
import lxml.html
from copy import deepcopy
from urlparse import urljoin
 
def fromstring(context, parser=None):
                    tag.text = ''
                tag.text += root_text
            if i > 0:
                root = deepcopy(list(root))
            tag.extend(root)
            root = tag[-len(root):]
        return self
            else:
                tag.text = root_text + tag.text
            if i > 0:
                root = deepcopy(list(root))
            tag[:0] = root
            root = tag[:len(root)]
        return self
                tag.tail = ''
            tag.tail += root_text
            if i > 0:
                root = deepcopy(list(root))
            parent = tag.getparent()
            index = parent.index(tag) + 1
            parent[index:index] = root
                    parent.text = ''
                parent.text += root_text
            if i > 0:
                root = deepcopy(list(root))
            parent = tag.getparent()
            index = parent.index(tag)
            parent[index:index] = root
        value = fromstring(value)[0]
        nodes = []
        for tag in self:
            wrapper = deepcopy(value)
            # FIXME: using iterchildren is probably not optimal
            if not wrapper.getchildren():
                wrapper.append(deepcopy(tag))
            else:
                childs = [c for c in wrapper.iterchildren()]
                child = childs[-1]
                child.append(deepcopy(tag))
 
        assert isinstance(value, basestring)
        value = fromstring(value)[0]
        wrapper = deepcopy(value)
        if not wrapper.getchildren():
            child = wrapper
        else:
 
        # add nodes to wrapper and check parent
        for tag in self:
            child.append(deepcopy(tag))
            if tag.getparent() is not parent:
                replace_childs = False
 
    def clone(self):
        """return a copy of nodes
        """
        self[:] = [deepcopy(tag) for tag in self]
        return self
 
    def empty(self):

src/n/i/nipy-HEAD/nipype/trunk/examples/spm_tutorial2.py   nipy(Download)
"""
 
from nipype.interfaces.base import Bunch
from copy import deepcopy
def subjectinfo(subject_id):
    print "Subject ID: %s\n"%str(subject_id)
    output = []
    names = ['Task-Odd','Task-Even']
    for r in range(4):
        onsets = [range(15,240,60),range(45,240,60)]
        output.insert(r,
                      Bunch(conditions=names,
                            onsets=deepcopy(onsets),

src/n/i/nipy-HEAD/nipype/trunk/examples/spm_tutorial.py   nipy(Download)
"""
 
from nipype.interfaces.base import Bunch
from copy import deepcopy
def subjectinfo(subject_id):
    print "Subject ID: %s\n"%str(subject_id)
    output = []
    names = ['Task-Odd','Task-Even']
    for r in range(4):
        onsets = [range(15,240,60),range(45,240,60)]
        output.insert(r,
                      Bunch(conditions=names,
                            onsets=deepcopy(onsets),

src/n/i/nipy-HEAD/nipype/trunk/examples/fsl_tutorial2.py   nipy(Download)
"""
 
from nipype.interfaces.base import Bunch
from copy import deepcopy
def subjectinfo(subject_id):
    print "Subject ID: %s\n"%str(subject_id)
    output = []
    names = ['Task-Odd','Task-Even']
    for r in range(4):
        onsets = [range(15,240,60),range(45,240,60)]
        output.insert(r,
                      Bunch(conditions=names,
                            onsets=deepcopy(onsets),

src/n/i/nipy-HEAD/nipype/trunk/examples/freesurfer_tutorial.py   nipy(Download)
"""
 
from nipype.interfaces.base import Bunch
from copy import deepcopy
def subjectinfo(subject_id):
    print "Subject ID: %s\n"%str(subject_id)
    output = []
    names = ['Task-Odd','Task-Even']
    for r in range(4):
        onsets = [range(15,240,60),range(45,240,60)]
        output.insert(r,
                      Bunch(conditions=names,
                            onsets=deepcopy(onsets),

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next