Re: [Tutor] Immutable objects

2010-08-19 Thread Nitin Das
Thanks guys, NamedTuple implementation is preety nice solution. --nitin On Thu, Aug 19, 2010 at 6:28 PM, Peter Otten <__pete...@web.de> wrote: > Peter Otten wrote: > > > Nitin Das wrote: > > > >> class mymut(object): > >> > >> def __setattr__(self,k,v): > >> if hasattr(self,k): > >>

Re: [Tutor] Immutable objects

2010-08-19 Thread Peter Otten
Peter Otten wrote: > Nitin Das wrote: > >> class mymut(object): >> >> def __setattr__(self,k,v): >> if hasattr(self,k): >> if self.__dict__.get(k) == None: >> self.__dict__[k] = v >> else: >> raise TypeError("Cant Modify Attribute Value") >

Re: [Tutor] Immutable objects

2010-08-19 Thread Peter Otten
Nitin Das wrote: > class mymut(object): > > def __setattr__(self,k,v): > if hasattr(self,k): > if self.__dict__.get(k) == None: > self.__dict__[k] = v > else: > raise TypeError("Cant Modify Attribute Value") > else: > raise T

Re: [Tutor] Immutable objects

2010-08-19 Thread Steven D'Aprano
On Thu, 19 Aug 2010 01:24:11 pm Nitin Das wrote: > Hello, > > Can somebody help me how to make immutable objects in python. I > have seen overriding the __new__, __setattr__ methods.. but not > comfortable with how to use them to make the object immutable. > > thanks in advance > --nitin I ha

Re: [Tutor] Immutable objects

2010-08-19 Thread Alan Gauld
"Nitin Das" wrote class mymut(object): def __setattr__(self,k,v): if hasattr(self,k): if self.__dict__.get(k) == None: self.__dict__[k] = v Do you need to look up the dict? Surely you could just use if self.k is None self.k = v which looks a lot simpler to

Re: [Tutor] Immutable objects

2010-08-18 Thread Nitin Das
class mymut(object): def __setattr__(self,k,v): if hasattr(self,k): if self.__dict__.get(k) == None: self.__dict__[k] = v else: raise TypeError("Cant Modify Attribute Value") else: raise TypeError("Immutable Object") class m

[Tutor] Immutable objects

2010-08-18 Thread Nitin Das
Hello, Can somebody help me how to make immutable objects in python. I have seen overriding the __new__, __setattr__ methods.. but not comfortable with how to use them to make the object immutable. thanks in advance --nitin ___ Tutor maillist - T

Re: [Tutor] immutable objects

2006-11-01 Thread Premnath Sah
 On 11/1/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > here is the stack> trace. i know that SOAPpy is doing wrong by not checking the type of> the element along with id(ele).> I thought if there is any work around the problem i could use that without > upgrading SOAPpy after it is fixed.Hi Premnath,Y

Re: [Tutor] immutable objects

2006-11-01 Thread Danny Yoo
> here is the stack > trace. i know that SOAPpy is doing wrong by not checking the type of > the element along with id(ele). > I thought if there is any work around the problem i could use that without > upgrading SOAPpy after it is fixed. Hi Premnath, You might want to see if some other SOAP mod

Re: [Tutor] immutable objects

2006-10-31 Thread Premnath Sah
On 10/31/06, Danny Yoo <[EMAIL PROTECTED]> wrote: > Im facing a problem with SOAPpy which checks for recursive objects using> id(obj).>> In my case value for 2 SOAP headers are same and iam getting a recursion> error. if i pass different object with same value SOAPpy does not complain > (by using s

Re: [Tutor] immutable objects

2006-10-31 Thread Danny Yoo
> Im facing a problem with SOAPpy which checks for recursive objects using > id(obj). > > In my case value for 2 SOAP headers are same and iam getting a recursion > error. if i pass different object with same value SOAPpy does not complain > (by using str(value) and unicode(value)). If you can inc

Re: [Tutor] immutable objects

2006-10-31 Thread Kent Johnson
Premnath Sah wrote: > I would like to know how i can guarantee that a new immutable object is > infact a new object. > > Example: > > >>> a = 1 > >>> b = 1 > >>> a is b > True > > is what i get. i want a and b to be two different object. I don't think there is any way to control this for th

Re: [Tutor] immutable objects

2006-10-31 Thread Premnath Sah
On 10/31/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Premnath Sah wrote:> I would like to know how i can guarantee that a new immutable object is> infact a new object.>> Example:>>  >>> a = 1>  >>> b = 1 >  >>> a is b> True>> is what i get. i want a and b to be two different object.I don't think th

[Tutor] immutable objects

2006-10-31 Thread Premnath Sah
Hi,from http://docs.python.org/ref/objects.htm """Types affect almost all aspects of object behavior. Even the importance of object identity is affected in some sense: for immutable types, operations that compute new values may actually return a reference to any existing object with the same type a