English 中文(简体)
贵重拷贝、深度和正常派任业务有何区别?
原标题:What is the difference between shallow copy, deepcopy and normal assignment operation?
import copy

a = "deepak"
b = 1, 2, 3, 4
c = [1, 2, 3, 4]
d = {1: 10, 2: 20, 3: 30}

a1 = copy.copy(a)
b1 = copy.copy(b)
c1 = copy.copy(c)
d1 = copy.copy(d)


print("immutable - id(a)==id(a1)", id(a) == id(a1))
print("immutable - id(b)==id(b1)", id(b) == id(b1))
print("mutable - id(c)==id(c1)", id(c) == id(c1))
print("mutable - id(d)==id(d1)", id(d) == id(d1))

我取得了以下成果:

immutable - id(a)==id(a1) True
immutable - id(b)==id(b1) True
mutable - id(c)==id(c1) False
mutable - id(d)==id(d1) False

如果我做了深入细微的工作:

a1 = copy.deepcopy(a)
b1 = copy.deepcopy(b)
c1 = copy.deepcopy(c)
d1 = copy.deepcopy(d)

结果相同:

immutable - id(a)==id(a1) True
immutable - id(b)==id(b1) True
mutable - id(c)==id(c1) False
mutable - id(d)==id(d1) False

如果我从事派任业务:

a1 = a
b1 = b
c1 = c
d1 = d

结果是:

immutable - id(a)==id(a1) True
immutable - id(b)==id(b1) True
mutable - id(c)==id(c1) True
mutable - id(d)==id(d1) True

有些人可以解释,复制件之间究竟有什么区别? 它是否与 mu和不可变物体有关? 如果是,请向我解释?

最佳回答

正常的派任业务将简单地把新的变数点到现有目标。 rel=“noreferer”>docs 2. 解释彩虹和深本之间的区别:

The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances):

  • 一份浅印件构造了一个新化合物,然后(尽可能)在其中添加对原始物体的提及。

  • A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.

这里只举几个例子:

import copy

a = [1, 2, 3]
b = [4, 5, 6]
c = [a, b]

使用正常转让操作方式复制:

d = c

print id(c) == id(d)          # True - d is the same object as c
print id(c[0]) == id(d[0])    # True - d[0] is the same object as c[0]

a. 使用浅印本:

d = copy.copy(c)

print id(c) == id(d)          # False - d is now a new object
print id(c[0]) == id(d[0])    # True - d[0] is the same object as c[0]

a. 使用深度拷贝:

d = copy.deepcopy(c)

print id(c) == id(d)          # False - d is now a new object
print id(c[0]) == id(d[0])    # False - d[0] is now a new object
问题回答

对于不可改变的物体,没有必要复制,因为数据永远不会改变,因此,Khury使用同样的数据;女方总是一样。 对于变标物体,由于它们可能发生变化,[吸入]复制件产生了一个新的物体。

深度拷贝与nes结构有关。 如果有名单,则深度<代码>。 该清单也是一份复读的副本。 仅有一份副本,你有一份新的外部名单,但内部名单是参考文件。

转让不复制。 它只是提到旧数据。 因此,你需要一份新清单,内容相同。

对于不可改变的物体,造出一份复制件就没有什么意义,因为它们不会改变。 关于 mu物体,https://docs.python.org/3/fer/simple_stmts.html#assignment-statements”rel=“nofollow noreferer”>,,https://docs.python.org/3/library/copy.html#copy.copy.copy.copycopy.copycopy.copycopy.cop=/code<>/code/p>/pdpyrecode.html#ry/pyrepyrep.html。 情况不同。 让我们以实例谈论其中每一个问题。

转让业务只是将来源的参考权转让给目的地,例如:

>>> i = [1,2,3]
>>> j=i
>>> hex(id(i)), hex(id(j))
>>> ( 0x10296f908 ,  0x10296f908 ) #Both addresses are identical

Now i and j technically refer to the same list. Both i and j have the same memory address. Any update to one of them will be reflected in the other, e.g:

>>> i.append(4)
>>> j
>>> [1,2,3,4] #Destination is updated

>>> j.append(5)
>>> i
>>> [1,2,3,4,5] #Source is updated

On the other hand, copy and deepcopy create a new copy of the variable. So now changes to the original variable will not be reflected in the copy variable and vice versa. However, copy(shallow copy) doesn t create a copy of nested objects, instead it just copies the references to the nested objects, while deepcopy(deep copy) copies all the nested objects recursively.

展示<代码>copydeepcopy的一些例子:

www.un.org/Depts/DGACM/index_spanish.htm 采用<代码>copy的固定名单实例:

>>> import copy
>>> i = [1,2,3]
>>> j = copy.copy(i)
>>> hex(id(i)), hex(id(j))
>>> ( 0x102b9b7c8 ,  0x102971cc8 ) #Both addresses are different

>>> i.append(4)
>>> j
>>> [1,2,3] #Update of original list didn t affect the copied variable

www.un.org/Depts/DGACM/index_spanish.htm 采用<代码>copy的 Nest:

>>> import copy
>>> i = [1,2,3,[4,5]]
>>> j = copy.copy(i)

>>> hex(id(i)), hex(id(j))
>>> ( 0x102b9b7c8 ,  0x102971cc8 ) #Both addresses are still different

>>> hex(id(i[3])), hex(id(j[3]))
>>> ( 0x10296f908 ,  0x10296f908 ) #Nested lists have the same address

>>> i[3].append(6)
>>> j
>>> [1,2,3,[4,5,6]] #Update of original nested list updated the copy as well

www.un.org/Depts/DGACM/index_spanish.htm 采用<条码>标准范围:<>

>>> import copy
>>> i = [1,2,3]
>>> j = copy.deepcopy(i)
>>> hex(id(i)), hex(id(j))
>>> ( 0x102b9b7c8 ,  0x102971cc8 ) #Both addresses are different

>>> i.append(4)
>>> j
>>> [1,2,3] #Update of original list didn t affect the copied variable

www.un.org/Depts/DGACM/index_spanish.htm 采用<条码>方法的 Nest名单实例:

>>> import copy
>>> i = [1,2,3,[4,5]]
>>> j = copy.deepcopy(i)

>>> hex(id(i)), hex(id(j))
>>> ( 0x102b9b7c8 ,  0x102971cc8 ) #Both addresses are still different

>>> hex(id(i[3])), hex(id(j[3]))
>>> ( 0x10296f908 ,  0x102b9b7c8 ) #Nested lists have different addresses

>>> i[3].append(6)
>>> j
>>> [1,2,3,[4,5]] #Update of original nested list didn t affect the copied variable    

a, b, c, d, a1, b1, c1, c1和d1指其母体独特识别的记忆物体。

一项转让行动提及该物体,并指定该名称为新名称。 c=[1,2,3,4],是一项任务,创造了一个包含这4个分类账的新清单标本,并将提及该标的条目指定为c。 <代码>c1=c系指对同一物体的同一提及,并指定<代码>c1。 由于该清单是多余的,无论你是否通过<代码>c或c1进入该名单,都会发现该名单的任何情况,因为它们都提到了同一目标。

c1=copy.copy.copy(c) 是一份“吸入拷贝”,其中列出了一个新的清单,并将新名单的提及指定到c1。 <代码>c仍然注明原始名单。 因此,如果你在<代码>c1上修改名单,那么<代码>c的名单中就不作改动。

复制的概念与ger类可变物体无关。 由于你可以更改这些物体,因此永远不需要在不同的地点有两本相同的记忆。 因此,简单地重新调配了复制概念不适用的愤怒和扼杀以及其他一些物体。 因此,您在<代码>a和b上的事例可得出相同之处。

c1=copy.deepcopy (c) is a “deep拷贝”,但功能与本例的浅拷贝相同。 深度拷贝不同于浅印本,因为浅印本将复制新标本,但任何参考资料in本身不会复制。 举例来说,您的名单上只字不提(不可改变),正如先前所讨论的那样,没有必要复制这些字。 因此,深度拷贝的“去掉”部分不适用。 然而,认为这一清单更为复杂:

e = [[1, 2],[4, 5, 6],[7, 8, 9]]

这份清单载有其他清单(青年也可将其描述为一个两维阵列)。

如果您在<代码>e上操作一个“短拷贝”,将其复制到e1,你就会发现,名单改动的背后之处,但清单的每一份都提到了同一三份清单——内有星号的清单。 这意味着,如果您要填写e[0].append(3)/code>,那么e[1, 2, 3],[4,5, 6],[7,8, 9]。 But e1 还将有<条码>[第1条、第2条、第3条]、[第4条、第5条、第6条]、[第7条、第8条]/代码。 另一方面,如果您随后填写了e.append([10、11、12]),e[1、2、3]、[4、5、6]、[7、8、9]、[10、11、12]。 But e1 仍为<代码>[1,2,3],[4,5,6],[7,8,9] 这是因为,外部清单是单独的物体,最初每个条目中有三个条目。 如果您通过一份或一份复印件来查阅这些改动,你就可以看到这些改动。 但是,如果你对上述一份外部名单进行修改,那么e则载有对原始三份名单的三处提及,并再提及一份新名单。 <代码>e1仍然仅载有三个原始参考资料。

一份深厚的复印件不仅将重复外部清单,而且还将放在清单内并重复内部清单,以便所产生的两个物体不包含任何相同的参考资料(就变性物体而言)。 如果内部清单内有进一步清单(或如字典等其他物体),这些清单也会重复。 这占了深处。

In python, when we assign objects like list, tuples, dict, etc to another object usually with a = sign, python creates copy’s by reference. That is, let’s say we have a list of list like this :

list1 = [ [  a  ,  b  ,  c  ] , [  d  ,  e  ,  f  ]  ]

我们为这一清单指定了另一个名单,如:

list2 = list1

then if we print list2 in python terminal we’ll get this :

list2 = [ [  a ,  b ,  c ] , [  d ,  e ,   f  ]  ]

Both list1 & list2 are pointing to same memory location, any change to any one them will result in changes visible in both objects, i.e both objects are pointing to same memory location. If we change list1 like this :

list1[0][0] =  x’
list1.append( [  g ] )

之后,清单1和清单2都将是:

list1 = [ [  x ,  b ,  c ] , [  d ,  e ,   f  ] , [  g ] ]
list2 = [ [  x ,  b ,  c ] , [  d ,  e ,   f  ] , [  g’ ] ]

Now coming to Shallow copy, when two objects are copied via shallow copy, the child object of both parent object refers to same memory location but any further new changes in any of the copied object will be independent to each other. Let’s understand this with a small example. Suppose we have this small code snippet :

import copy

list1 = [ [  a ,  b ,  c ] , [  d ,  e ,   f  ]  ]      # assigning a list
list2 = copy.copy(list1)       # shallow copy is done using copy function of copy module

list1.append ( [  g ,  h ,  i ] )   # appending another list to list1

print list1
list1 = [ [  a ,  b ,  c ] , [  d ,  e ,   f  ] , [  g ,  h ,  i ] ]
list2 = [ [  a ,  b ,  c ] , [  d ,  e ,   f  ] ]

通知、名单2仍然未受影响,但如果我们改变诸如:

list1[0][0] =  x’

之后,清单1和清单2都将发生变化:

list1 = [ [  x ,  b ,  c ] , [  d ,  e ,   f  ] , [  g ,  h ,  i ] ] 
list2 = [ [  x ,  b ,  c ] , [  d ,  e ,   f  ] ]

Now, Deep copy helps in creating completely isolated objects out of each other. If two objects are copied via Deep Copy then both parent & it’s child will be pointing to different memory location. Example :

import copy

list1 = [ [  a ,  b ,  c ] , [  d ,  e ,   f  ]  ]         # assigning a list
list2 = deepcopy.copy(list1)       # deep copy is done using deepcopy function of copy module

list1.append ( [  g ,  h ,  i ] )   # appending another list to list1

print list1
list1 = [ [  a ,  b ,  c ] , [  d ,  e ,   f  ] , [  g ,  h ,  i ] ]
list2 = [ [  a ,  b ,  c ] , [  d ,  e ,   f  ] ]

通知、名单2仍然未受影响,但如果我们改变诸如:

list1[0][0] =  x’

因此,清单2也将不受影响,因为所有儿童物体和母物体都位于不同的记忆点:

list1 = [ [  x ,  b ,  c ] , [  d ,  e ,   f  ] , [  g ,  h ,  i ] ] 
list2 = [ [  a ,  b ,  c ] , [  d ,  e ,   f    ] ]

希望会有所助益。

Deep copy is related to nested structures. If you have list of lists, then deepcopy copies the nested lists also, so it is a recursive copy. With just copy, you have a new outer list, but inner lists are references. Assignment does not copy. For Ex

import copy
spam = [[0, 1, 2, 3], 4, 5]
cheese = copy.copy(spam)
cheese.append(3)
cheese[0].append(3)
print(spam)
print(cheese)

<<>OutPut

[[0, 1, 2, 3, 3], 4, 5] [[0, 1, 2, 3, 3], 4, 5, 3] Copy method copy content of outer list to new list but inner list is still same for both list so if you make changes in inner list of any lists it will affects both list.

但是,如果你使用的话,你会使用你。 之后,还将为内部名单创造新的理由。

import copy
spam = [[0, 1, 2, 3], 4, 5]
cheese = copy.deepcopy(spam)
cheese.append(3)
cheese[0].append(3)
print(spam)
print(cheese)

<><>Output

[0, 1, 2, 3] [[0, 1, 2, 3, 3], 4, 5, 3]

下面的代码显示了转让、使用复制方法复制的浅印、使用(slice)的浅印[:]和深度。 下面的例子通过使差异更为明显而采用nes名单。

from copy import deepcopy

########"List assignment (does not create a copy) ############
l1 = [1,2,3, [4,5,6], [7,8,9]]
l1_assigned = l1

print(l1)
print(l1_assigned)

print(id(l1), id(l1_assigned))
print(id(l1[3]), id(l1_assigned[3]))
print(id(l1[3][0]), id(l1_assigned[3][0]))

l1[3][0] = 100
l1.pop(4)
l1.remove(1)


print(l1)
print(l1_assigned)
print("###################################")

########"List copy using copy method (shallow copy)############

l2 = [1,2,3, [4,5,6], [7,8,9]]
l2_copy = l2.copy()

print(l2)
print(l2_copy)

print(id(l2), id(l2_copy))
print(id(l2[3]), id(l2_copy[3]))
print(id(l2[3][0]), id(l2_copy[3][0]))
l2[3][0] = 100
l2.pop(4)
l2.remove(1)


print(l2)
print(l2_copy)

print("###################################")

########"List copy using slice (shallow copy)############

l3 = [1,2,3, [4,5,6], [7,8,9]]
l3_slice = l3[:]

print(l3)
print(l3_slice)

print(id(l3), id(l3_slice))
print(id(l3[3]), id(l3_slice[3]))
print(id(l3[3][0]), id(l3_slice[3][0]))

l3[3][0] = 100
l3.pop(4)
l3.remove(1)


print(l3)
print(l3_slice)

print("###################################")

########"List copy using deepcopy ############

l4 = [1,2,3, [4,5,6], [7,8,9]]
l4_deep = deepcopy(l4)

print(l4)
print(l4_deep)

print(id(l4), id(l4_deep))
print(id(l4[3]), id(l4_deep[3]))
print(id(l4[3][0]), id(l4_deep[3][0]))

l4[3][0] = 100
l4.pop(4)
l4.remove(1)

print(l4)
print(l4_deep)
print("##########################")
print(l4[2], id(l4[2]))
print(l4_deep[3], id(l4_deep[3]))

print(l4[2][0], id(l4[2][0]))
print(l4_deep[3][0], id(l4_deep[3][0]))

The GIST to take is this: Dealing with shallow lists (no sub_lists, just single elements) using "normal assignment" rises a "side effect" when you create a shallow list and then you create a copy of this list using "normal assignment". This "side effect" is when you change any element of the copy list created, because it will automatically change the same elements of the original list. That is when copy comes in handy, as it won t change the original list elements when changing the copy elements.

On the other hand, copy does have a "side effect" as well, when you have a list that has lists in it (sub_lists), and deepcopy solves it. For instance if you create a big list that has nested lists in it (sub_lists), and you create a copy of this big list (the original list). The "side effect" would arise when you modify the sub_lists of the copy list which would automatically modify the sub_lists of the big list. Sometimes (in some projects) you want to keep the big list (your original list) as it is without modification, and all you want is to make a copy of its elements (sub_lists). For that, your solution is to use deepcopy which will take care of this "side effect" and makes a copy without modifying the original content.

<代码>copy和deep份业务仅涉及复合物体(即:含有其他物体的物体,如清单)。

下面是这一简单法典例子所显示的差别:

<><>>>>>>>>

请通过创建原始名单和这份名单的复印件,检查<代码>copy(鲸目):

import copy
original_list = [1, 2, 3, 4, 5, [ a ,  b ]]
copy_list = copy.copy(original_list)

现在,请进行一些<代码>的印本/编码>测试,并了解原始清单与其复印清单的对比:

原件_清单和副本-清单有不同的地址

print(hex(id(original_list)), hex(id(copy_list))) # 0x1fb3030 0x1fb3328

原件——清单和复印件——清单内容相同

print(hex(id(original_list[1])), hex(id(copy_list[1]))) # 0x537ed440 0x537ed440

sub_原件——清单和复印件——清单内容相同

print(hex(id(original_list[5])), hex(id(copy_list[5]))) # 0x1faef08 0x1faef08

更改原清单内容的NOT修改了正本-清单内容

original_list.append(6)
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ]]

更改正本-清单内容,NOT修改原清单内容

copy_list.append(7)
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ], 7]

修改原有的“名单”子_elements

original_list[5].append( c )
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ,  c ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ,  c ], 7]

modifying copy_list sub_elements automatically modify original_list sub_elements

copy_list[5].append( d )
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ,  c ,  d ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ,  c ,  d ], 7]

<><>>>><>>>>>>>><>>>>>>

让我们检查一下<条码>处理范围广的,与我们在<条码>上所做的那样做。 (填写一份清单和一份清单):

import copy
original_list = [1, 2, 3, 4, 5, [ a ,  b ]]
copy_list = copy.copy(original_list)

现在,请进行一些<代码>的印本/编码>测试,并了解原始清单与其复印清单的对比:

import copy
original_list = [1, 2, 3, 4, 5, [ a ,  b ]]
copy_list = copy.deepcopy(original_list)

原件_清单和副本-清单有不同的地址

print(hex(id(original_list)), hex(id(copy_list))) # 0x1fb3030 0x1fb3328

原件——清单和复印件——清单内容相同

print(hex(id(original_list[1])), hex(id(copy_list[1]))) # 0x537ed440 0x537ed440

sub_elements of 原件_清单和副本-清单有不同的地址

print(hex(id(original_list[5])), hex(id(copy_list[5]))) # 0x24eef08 0x24f3300

更改原清单内容的NOT修改了正本-清单内容

original_list.append(6)
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ]]

更改正本-清单内容,NOT修改原清单内容

copy_list.append(7)
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ], 7]

NOT修改了原“名单子”

original_list[5].append( c )
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ,  c ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ], 7]

更改名单

copy_list[5].append( d )
print("original_list is:", original_list) # original_list is: [1, 2, 3, 4, 5, [ a ,  b ,  c ,  d ], 6]
print("copy_list is:", copy_list) # copy_list is: [1, 2, 3, 4, 5, [ a ,  b ,  d ], 7]

The following code shows how underlying addresses are affected in copy, deepcopy and assignment. This is similar to what Sohaib Farooqi showed with lists, but with classes.

from copy import deepcopy, copy

class A(object):
    """docstring for A"""
    def __init__(self):
        super().__init__()

class B(object):
    """docstring for B"""
    def __init__(self):
        super().__init__()
        self.myA = A()

a = B()
print("a is", a)
print("a.myA is", a.myA)
print("After copy")
b = copy(a)
print("b is", b)
print("b.myA is", b.myA)
b.myA = A()
print("-- after changing value")
print("a is", a)
print("a.myA is", a.myA)
print("b is", b)
print("b.myA is", b.myA)

print("Resetting")
print("*"*40)
a = B()
print("a is", a)
print("a.myA is", a.myA)
print("After deepcopy")
b = deepcopy(a)
print("b is", b)
print("b.myA is", b.myA)
b.myA = A()
print("-- after changing value")
print("a is", a)
print("a.myA is", a.myA)
print("b is", b)
print("b.myA is", b.myA)

print("Resetting")
print("*"*40)
a = B()
print("a is", a)
print("a.myA is", a.myA)
print("After assignment")
b = a
print("b is", b)
print("b.myA is", b.myA)
b.myA = A()
print("-- after changing value")
print("a is", a)
print("a.myA is", a.myA)
print("b is", b)
print("b.myA is", b.myA)

该法典的产出如下:

a is <__main__.B object at 0x7f1d8ff59760>
a.myA is <__main__.A object at 0x7f1d8fe8f970>
After copy
b is <__main__.B object at 0x7f1d8fe43280>
b.myA is <__main__.A object at 0x7f1d8fe8f970>
-- after changing value
a is <__main__.B object at 0x7f1d8ff59760>
a.myA is <__main__.A object at 0x7f1d8fe8f970>
b is <__main__.B object at 0x7f1d8fe43280>
b.myA is <__main__.A object at 0x7f1d8fe85820>
Resetting
****************************************
a is <__main__.B object at 0x7f1d8fe85370>
a.myA is <__main__.A object at 0x7f1d8fe43310>
After deepcopy
b is <__main__.B object at 0x7f1d8fde3040>
b.myA is <__main__.A object at 0x7f1d8fde30d0>
-- after changing value
a is <__main__.B object at 0x7f1d8fe85370>
a.myA is <__main__.A object at 0x7f1d8fe43310>
b is <__main__.B object at 0x7f1d8fde3040>
b.myA is <__main__.A object at 0x7f1d8fe43280>
Resetting
****************************************
a is <__main__.B object at 0x7f1d8fe432b0>
a.myA is <__main__.A object at 0x7f1d8fe85820>
After assignment
b is <__main__.B object at 0x7f1d8fe432b0>
b.myA is <__main__.A object at 0x7f1d8fe85820>
-- after changing value
a is <__main__.B object at 0x7f1d8fe432b0>
a.myA is <__main__.A object at 0x7f1d8fe85370>
b is <__main__.B object at 0x7f1d8fe432b0>
b.myA is <__main__.A object at 0x7f1d8fe85370>
>>lst=[1,2,3,4,5]

>>a=lst

>>b=lst[:]

>>> b
[1, 2, 3, 4, 5]

>>> a
[1, 2, 3, 4, 5]

>>> lst is b
False

>>> lst is a
True

>>> id(lst)
46263192

>>> id(a)
46263192 ------>  See here id of a and id of lst is same so its called deep copy and even boolean answer is true

>>> id(b)
46263512 ------>  See here id of b and id of lst is not same so its called shallow copy and even boolean answer is false although output looks same.

Not sure if it mentioned above or not, but it s very importable to undestand that .copy() create reference to original object. If you change copied object - you change the original object. .deepcopy() creates new object and does real copying of original object to new one. Changing new deepcopied object doesn t affect original object.

是的, .deepcopy()复制原物体复读, 而copy()则对原物体的第一层数据设定参考反对。

So the copying/referencing difference between .copy() and .deepcopy() is significant.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签