If you want to setup / tear-down, use with; so, if a is an instance of a class, Aclass:
with Aclass() as a: b(a) a.member_b() # now Aclass object is freed, and any cleanup or passed on exceptions which were raised and not handled are here. On Mon, Jul 13, 2009 at 7:36 PM, mdipierro <mdipie...@cs.depaul.edu> wrote: > > Say I do > > with a: > b() > > Perhaps I am mistaken but I do not see a way for b to refer to a. Say > a contains a counter. I would like b() to increment that counter. How > do I do it without explicitly passing a to b? > > Massimo > > On Jul 13, 7:24 pm, Yarko Tymciurak <yark...@gmail.com> wrote: > > Re: Proposed syntax - I might agree; it is just a request for syntax (I > to > > don't see the motivation, other than - as Joe says - sytactic sugar;) > > > > Re: with statement - I think it has uses, and I can see immediately one > > place I would put it in, and could probably find a few more places where > it > > would be of good use. > > > > On Mon, Jul 13, 2009 at 7:15 PM, mdipierro <mdipie...@cs.depaul.edu> > wrote: > > > > > I repeat. I do not see how it would be possible to implement the > > > proposed syntax without major changes in the definition of the helpers > > > and that would be slow when compared with the current implementation. > > > Perhaps I am wrong. > > > > > Whether or not this is a good idea, if I am wrong, I would like to see > > > a patch that implements this for the DIV helper. > > > > > Massimo > > > > > On Jul 13, 7:07 pm, Yarko Tymciurak <yark...@gmail.com> wrote: > > > > I think you are both missing important point: > > > > > > classes which support context would be able to be used in "with" > > > contexts"; > > > > Nothing would be more complex or slower - you'd only use it to make > > > things > > > > cleaner (move code into class _enter_() and _exit_() methods, which > would > > > > only get called (I presume) on with use anyway... If you have the > code > > > in > > > > one place instead of scattered, there is nothing slower or more > complex - > > > to > > > > the contrary. > > > > > > I would agree with you that this could get overused in places (e.g. > if it > > > > were used as "syntactic sugar") - but that is a different story. > > > > > > cvs reader and writer - I had trouble (had to "hack" a fix) with this > in > > > the > > > > registration system; I never provided a patch, because could not see > a > > > > good, clean way to decouple application setup from gluon --- THIS is > a > > > way > > > > to do that. > > > > > > I'm pretty sure if I looked, I'd find a few (not many maybe, but a > few) > > > > places this would be a good idea, solve existing problems. > > > > > > I think both of you need to just consider this a little more > carefully, > > > > that's all... > > > > > > - Yarko > > > > > > On Mon, Jul 13, 2009 at 7:00 PM, mdipierro <mdipie...@cs.depaul.edu> > > > wrote: > > > > > > > I agree with Joe. It require making object context dependent whoch > > > > > would make things unnecessarily more complex and slower. > > > > > > > On Jul 13, 6:42 pm, Joe Barnhart <joe.barnh...@gmail.com> wrote: > > > > > > I see no benefit to using PEP343 just to provide syntactic sugar > for > > > > > > this purpose. There is no REASON to use the "with" statement > because > > > > > > we're not doing anything with exception handling here. It's only > > > > > > being used to create an input format that looks prettier to some > > > eyes. > > > > > > > > Am I missing something?? > > > > > > > > On Jul 13, 2:40 pm, Yarko Tymciurak <yark...@gmail.com> wrote: > > > > > > > > > There are 2 interesting aspects from Luis's blogger post: > > > > > > > > > - to use with, classes need to consider contexts; > > > > > > > - the (to me, at least) interesting example of ASP.NET's > xmlwriter > > > > > class > > > > > > > (generating SVG dynamically) is... .NET specific; I'm off busy > > > looking > > > > > for > > > > > > > a python portable idiom to use in place of his last example... > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---