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

All Samples(8425)  |  Call(7279)  |  Derive(0)  |  Import(1146)
Shallow copy operation on arbitrary Python objects.

See the module's __doc__ string for more info.

        def copy(x):
    """Shallow copy operation on arbitrary Python objects.

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

    cls = type(x)

    copier = _copy_dispatch.get(cls)
    if copier:
        return copier(x)

    copier = getattr(cls, "__copy__", None)
    if copier:
        return copier(x)

    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(shallow)copyable object of type %s" % cls)

    return _reconstruct(x, rv, 0)
        


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)
# nested lists:
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)

src/s/h/shedskin-HEAD/examples/bh.py   shedskin(Download)
 
from time import clock
from sys import stderr, maxint, argv
from copy import copy
from math import sqrt, pi, floor
 
class Random(object):
        self.pskip = b
 
        # Poat which to evaluate field
        self.pos0 = copy(p)
 
        # Computed potential at pos0
        self.phi0 = 0.0
    def vp(bodies, nstep):
        dacc = Vec3()
        dvel = Vec3()
        dthf = 0.5 * BH.DTIME
 
        for b in reversed(bodies):
            acc1 = copy(b.new_acc)
            if nstep > 0:
                dacc.subtraction2(acc1, b.acc)
                dvel.mult_scalar2(dacc, dthf)
                dvel += b.vel
                b.vel = copy(dvel)
 
            b.acc = copy(acc1)
            b.acc = copy(acc1)
            dvel.mult_scalar2(b.acc, dthf)
 
            vel1 = copy(b.vel)
            vel1 += dvel
            dpos = copy(vel1)
            dpos *= BH.DTIME
            dpos += b.pos
            b.pos = copy(dpos)
            vel1 += dvel
            b.vel = copy(vel1)

src/s/h/shedskin-HEAD/examples/chess.py   shedskin(Download)
# 4x castling flags, indices [10-13], queen side white, king side white, queen side black, king side white
# turn, enpassant [26, 27]
 
from copy import copy
 
iNone = -999
iTrue = 1
  if board[26]:
    kingVal = -kingVal
  for mv in allMoves:
    board2 = copy(board)
    move(board2, mv)
    #print "trying to reduce move", toString(mv)
    if not [i for i in pseudoLegalCaptures(board2) if board2[i & 0xff] == kingVal]:
  if n >= -4:
    #from copy import copy
    for mv in pseudoLegalCaptures(board):
      newboard = copy(board)
      move(newboard, mv)
      value = alphaBetaQui(newboard, -beta, -alpha, n - 1)
      value = (-value[0], value[1])
  bestMove = iNone # XXX
 
  for mv in legalMoves(board):
    newboard = copy(board)
    move(newboard, mv)
    value = alphaBeta(newboard, -beta, -alpha, n - 1)
    value = (-value[0], value[1])

src/k/a/kamaelia-HEAD/trunk/Sketches/MPS/Examples/LUGRadio/likefile.py   kamaelia(Download)
        except KeyError, e:
            del inputComponent
            raise KeyError, 'component to wrap has no such outbox: %s' % e
        self.inQueues = copy.copy(inputComponent.inQueues)
        self.outQueues = copy.copy(outputComponent.outQueues)
        # reaching into the component and its child like this is threadsafe since it has not been activated yet.
        self.inputComponent = inputComponent

src/k/a/kamaelia-HEAD/Sketches/MPS/Examples/LUGRadio/likefile.py   kamaelia(Download)
        except KeyError, e:
            del inputComponent
            raise KeyError, 'component to wrap has no such outbox: %s' % e
        self.inQueues = copy.copy(inputComponent.inQueues)
        self.outQueues = copy.copy(outputComponent.outQueues)
        # reaching into the component and its child like this is threadsafe since it has not been activated yet.
        self.inputComponent = inputComponent

src/d/u/dushman-HEAD/applications/examples/controllers/appadmin.py   dushman(Download)
 
# ## critical --- make a copy of the environment
 
global_env = copy.copy(globals())
global_env['datetime'] = datetime
 
http_host = request.env.http_host.split(':')[0]
        'ratio': 0,
        'oldest': time.time()
    }
    disk = copy.copy(ram)
    total = copy.copy(ram)
 
    for key, value in cache.ram.storage.items():

src/s/c/scipy-HEAD/scipy/weave/examples/cast_copy_transpose.py   scipy(Download)
def _castCopyAndTranspose(type, *arrays):
    cast_arrays = ()
    import copy
    for a in arrays:
        if a.dtype == numpy.dtype(type):
            cast_arrays = cast_arrays + (copy.copy(numpy.transpose(a)),)
        else:
            cast_arrays = cast_arrays + (copy.copy(
                                       numpy.transpose(a).astype(type)),)

src/s/p/spike-HEAD/vendor/stackless/v2.5.1/Demo/tix/samples/DirTree.py   spike(Download)
                                  label.anchor w
                                  ''')
 
        self.dlist_dir = copy.copy(os.curdir)
        top.ent.entry['textvariable'] = self.dlist_dir
        top.btn['command'] = lambda dir=top.dir, ent=top.ent, self=self: \
                             self.copy_name(dir,ent)

src/s/p/spike-HEAD/vendor/stackless/v2.5.1/Demo/tix/samples/DirList.py   spike(Download)
        # font = self.root.master.tix_option_get('fixed_font')
        top.ent.entry['font'] = font
 
        self.dlist_dir = copy.copy(os.curdir)
        # This should work setting the entry's textvariable
        top.ent.entry['textvariable'] = self.dlist_dir
        top.btn['command'] = lambda dir=top.dir, ent=top.ent, self=self: \

src/s/p/spike-HEAD/vendor/stackless/current/Demo/tix/samples/DirTree.py   spike(Download)
                                  label.anchor w
                                  ''')
 
        self.dlist_dir = copy.copy(os.curdir)
        top.ent.entry['textvariable'] = self.dlist_dir
        top.btn['command'] = lambda dir=top.dir, ent=top.ent, self=self: \
                             self.copy_name(dir,ent)

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