[Tutor] immutable objects
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 and value, while for mutable objects this is not allowed. E.g., after "a = 1; b = 1", a and b may or may not refer to the same object with the value one, depending on the implementation, but after "c = []; d = []", c and d are guaranteed to refer to two different, unique, newly created empty lists. (Note that "c = d = []" assigns the same object to both c and d.)""" 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 bTrueis what i get. i want a and b to be two different object. Thanks in advancePremnath Sah T. H. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] immutable objects
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 there is any way to control this for the builtin types.Why do you care? 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)). ThanksPremnath Sah T. H. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] immutable objects
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 str(value) and unicode(value)).If you can include a stack trace of that error with SOAPpy, that would beexcellent. This sounds bizarre.You won't be able to do anything with the ints: some of them are internally interned by the runtime, and you can't control this. So I'dinstead focus on why SOAPpy is failing. It shouldn't have to worry aboutrecursively traversing the ints: they don't have any structure to traverse! So a stack trace would be useful.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. >>> import SOAPpy>>> rmt = SOAPpy.SOAPProxy(url, header = SOAPpy.Types.headerType(data="" 'prem', 'password': 'prem'}))Traceback (most recent call last): File "", line 1, in ? NameError: name 'url' is not defined>>> url = "" href="http://soap.test.com/">http://soap.test.com/">>> rmt = SOAPpy.SOAPProxy(url, header = SOAPpy.Types.headerType(data="" 'prem', 'password': 'prem'})) >>> rmt.testcall()Traceback (most recent call last): File "", line 1, in ? File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/Client.py", line 453, in __call__ return self.__r_call(*args, **kw) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/Client.py", line 475, in __r_callself.__hd, self.__ma) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/Client.py", line 338, in __call config = self.config, noroot = self.noroot) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 624, in buildSOAPreturn t.build() File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 112, in build self.dump(self.header, "Header", typed = typed) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 294, in dumpmeth(obj, tag, typed, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 580, in dump_instance self.dump(getattr(obj,k), k, typed, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 294, in dumpmeth(obj, tag, typed, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 358, in dump_string id = self.checkref(obj, tag, ns_map) File "/cv/vendor/lib/python2.4/site-packages/SOAPpy/SOAPBuilder.py", line 260, in checkrefraise RecursionError, "Cannot serialize recursive object" SOAPpy.Errors.RecursionError: >>>-- With Regards,Premnath Sah T. H. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] immutable objects
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,You might want to see if some other SOAP module might be better supported.The last version of SOAPpy that I've seen appears to have been released in 2005, and as far as I can tell, the project is languishing a bit. Most ofthe energy toward Python and SOAP seems to be focused on the Zolera SOAPInfrastructure (ZSI) project, which can be found at: http://pywebsvcs.sourceforge.net/Thanks again for the stack trace; it helps pinpoint some problems. I didsome quick checks on the stack trace; the line numbers from the stack trace aren't matching up with SOAPpy 0.12.0., so I'm not sure if thisproblem has already been fixed or not. You may want to make sure you havethe latest release of SOAPpy if you continue using that module. The code for SOAPBuilder.dump_string() just doesn't look right to me.Why does one have to do a checkref() on it when serializing the stringdata, given that a string has no internal structure to speak of? I think the code there is just wrong. You're seeing this failure simply becauseyou're passing in two strings with the same id, which should be perfectlylegal and fine. SOAPpy is definitely at fault here.I kludged up the recursive-checking code on strings ( i.e. turned it off),and now see the following:##>>> import SOAPpy>>> rmt = SOAPpy.SOAPProxy(" http://soap.test.com",...header = SOAPpy.Types.headerType(...data = "" 'prem',...'password': 'prem'})) >>> rmt.testcall()Traceback (most recent call last): File "", line 1, in ? File "SOAPpy/Client.py", line 470, in __call__ return self.__r_call(*args, **kw) File "SOAPpy/Client.py", line 492, in __r_call self.__hd, self.__ma) File "SOAPpy/Client.py", line 363, in __call config = self.config) File "SOAPpy/Client.py", line 263, in call raise HTTPError(code, msg)SOAPpy.Errors.HTTPError: ##which looks a little more promising. In fact, you can see this yourself by playing a small trick:###>>> rmt = SOAPpy.SOAPProxy(" http://soap.test.com", header =SOAPpy.Types.headerType(data="" 'p' + 'rem', 'password': 'p' +'rem'}))>>> rmt.testcall()Traceback (most recent call last): File "", line 1, in ? File "SOAPpy/Client.py", line 470, in __call__ return self.__r_call(*args, **kw) File "SOAPpy/Client.py", line 492, in __r_call self.__hd, self.__ma) File "SOAPpy/Client.py", line 363, in __call config = self.config) File "SOAPpy/Client.py", line 263, in call raise HTTPError(code, msg)SOAPpy.Errors.HTTPError: ### Forcing the manual string concatenation lets you go on, but this is just asilly kludge around what is fundamentally a bad SOAPYpy bug.My current recommendation is to try using ZSI instead: the SOAPpy code base appears to have a bit of bit rot.Good luck to you!Thanks for your reply. I will definitely look into ZSI -- With Regards,Premnath Sah T. H. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor