[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Concerning copy



Python's does pass by value, but the object is reference and if you modify it via a method it should be changed forever.

From http://www.poromenos.org/tutorials/python:

def func(arg):
    arg = ['another value']

value = ['original value']
func(value)
print value
['original value']

def func(arg):
    arg.append("value added by func")

value = ['original value']
func(value)
print value
['original value', 'value added by func']

Languages rarely have the ability to turn off "features" - akin to telling the English language not to have pronouns.

Nelson
http://www.tojam.ca

Kevin Turner <darian@xxxxxxxxxxxxx> wrote:
Recently I encountered an issue where Python would, instead of creating
a new object, instead reference the original one. Using copy.copy() is
a solution, but I'd much rather be able to toggle off the weird
referencing that Python has been using and make exceptions as
necessary. Is there any way to do this?



Celebrate Earth Day everyday! Discover 10 things you can do to help slow climate change. Yahoo! Earth Day