Re: Mk4py - Strange Behaviour when assigning views
Brian Kelley <[email protected]>
| Newsgroups | gmane.comp.db.metakit |
|---|---|
| Message-ID | <[email protected]> |
You problem is pretty simple, the storage you are declaring in make_view is being de-allocated when it goes out of scope. Move st=make.storage() to the top level as in import metakit.metakit as mk st = make.storage() That should fix the problem. Brian On Sun, 19 Sep 2004 09:24:26 -0400, choppystride <[email protected]> wrote: > Hi, > > Please look at the following code: > > import metakit.metakit as mk > > def make_view (): > st = mk.storage() > vw = st.getas( "test[val:I]" ) > > for i in xrange(3): vw.append( val=i ) > > print 'inside make_view():' > print ' view obj: ', vw > print ' structure: ', vw.structure() > for row in vw: print ' row.val= ', row.val > return vw > > def test1 (): > v2 = make_view() > print 'outside make_view()' > print ' view obj: ', v2 > print ' structure: ', v2.structure() > for row in v2: print ' row.val= ', row.val > > if __name__ == '__main__': > print 'metakit version ', mk.version > test1() > > When running the code, I got the following output & error: > > metakit version 2.4.9.3 > inside make_view(): > view obj: <PyView object at 8f95c0> > structure: [Property('I', 'val')] > row.val= 0 > row.val= 1 > row.val= 2 > outside make_view() > view obj: <PyView object at 8f95c0> > structure: [] > row.val= > Traceback (most recent call last): > File "test2.py", line 48, in ? > test1() > File "test2.py", line 21, in test1 > for row in v2: print ' row.val= ', row.val > AttributeError: val > > A similar problem occurs when I store the view as an instance var in > an object and then access it later: > > class testmk ( object ): > def __init__ ( self ): > st = mk.storage() > self.vw = st.getas( "test[val:I]" ) > for i in xrange(3): self.vw.append( val=i ) > > def prtvw ( self ): > print 'tmk view obj: ', self.vw > print 'tmk: structure: ', self.vw.structure() > for row in self.vw: print 'tmk: row.val= ', row.val > > def test_obj (): > tmk = testmk() > tmk.prtvw() > > if __name__ == '__main__': > print 'metakit version ', mk.version > test_obj() > > The resulting output and error are: > > metakit version 2.4.9.3 > tmk view obj: <PyView object at 8df7d0> > tmk: structure: [] > tmk: row.val= > Traceback (most recent call last): > File "test2.py", line 69, in ? > test_obj() > File "test2.py", line 65, in test_obj > tmk.prtvw() > File "test2.py", line 61, in prtvw > for row in self.vw: print 'tmk: row.val= ', row.val > AttributeError: val > > I can circumvent this problem by manipulating the storage object > instead. Then whenever I need the view, I can just call > storage.view(...). This seems to be OK. > > Am I doing something wrong or could there be a possible bug? > > I'm using Active Python v2.3.2 on Win XP. > > Thanks! > > -- > Cheers, > choppystride > > _____________________________________________ > Metakit mailing list - [email protected] > http://www.equi4.com/mailman/listinfo/metakit > _____________________________________________ Metakit mailing list - [email protected] http://www.equi4.com/mailman/listinfo/metakit