From: Jim A. <ji...@tr...> - 2001-03-28 04:20:47
|
"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... 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? -- __o Jim Adrig _ \<,_ ji...@tr... ' `/ ' ` ___________ `-' `-' |