member by member copy???

emile at fenx.com emile at fenx.com
Wed May 10 17:02:34 CEST 2000


You could create a separate instance, or provide a copy
function as part of the class.

>>> a = A('bragi')
>>> b = A('')
>>> b.name = a.name
>>> b.name
'bragi'
>>> a.name = 'stini'
>>> b.name
'bragi'
>>> 


>>> class A:
	def __init__(self,name):
		self.name = name
	def copy(self):
		retval = A(self.name)
		# other copy functions
		return retval

	
>>> a = A('bragi')
>>> b = a.copy()
>>> b.name
'bragi'
>>> a.name = 'stini'
>>> b.name
'bragi'
>>> 


HTH

Emile van Sebille
emile at fenx.com


<bragib at my-deja.com> wrote in message
news:<8fbska$4ti$1 at nnrp1.deja.com>...
> How do I copy on object into another without having them
> refer to each other.
> Example:
> 
> >>> class A:
> ...    def __init__(self,name):
> ...        self.name = name
> ...
> >>> a = A('bragi')
> >>> b = a
> >>> b.name
> 'bragi'
> >>> b.name= 'stina'
> >>> a.name
> 'stina'
> 
> I would have liked to see
> >>> a.name
> 'bragi'
> 
> How do I do this?
> 
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.
> -- 
> http://www.python.org/mailman/listinfo/python-list
>




More information about the Python-list mailing list