From: Robert W. B. <rb...@di...> - 2001-03-28 15:06:00
|
On Tue, 27 Mar 2001, Jim Adrig wrote: > "Robert W. Bill" wrote: > > > > Hi all, > > > > I've ran into a bit of confusion with the id() of characters in > > Jython compared with Python. Here's something similar to the code > > that started the confusion: > > > > ---------------------------------------------------------- > > S = "abc" > > L = ["a", "b", "c"] > > LoL = [L, L, L] > > stringtest = S[1] > > listtest = L[1] > > loltest = LoL[1] > > > > def test(obj1, obj2): > > if ( id(obj1) != id(obj2) ): > > return 0 > > > > assert(test(loltest, LoL[1])), "List-of-lists test failed" > > assert(test(listtest, L[1])), "List test failed" > > assert(test(stringtest, S[1])), "String test failed" > > ---------------------------------------------------------- > > > > In CPython, all passes, but in Jython, there's always an AE: > > String test failed. Is this expected? unavoidable? > > When I cut/paste this code directly into a file and run it, it fails on > the first line. Doesn't the 'test' need a 'else' part? I'm new to Python > but using Jython in a new project so correct me if I'm wrong... Yes, it does require else. No, you're definately not wrong. Sorry for the sloppiness in my post. > I used this instead: > > def test(obj1, obj2): > if ( id(obj1) != id(obj2) ): > return 0 > else: > return 1 > > And my version (2.1a1) passes ALL the tests. > > Am I missing something? No, you are not missing anything. All tests pass in 2.1a1. I had only tested 2.0. After looking further (guided by other's comments), I'm unsure if this id is supposed to be guaranteed in this situation anyway. tnx for the reply. Regards, Robert |