Makes much sense; thanks Nathan ! 2015-11-17 18:32 GMT+00:00 Nathan Rusch <nathan_ru...@hotmail.com>:
> These two snippets are pretty much functionally identical: > > with group: > # Do something... > > # ------ > > group.begin() > try: > # Do something... > finally: > group.end() > > > The `with`statement works with objects that implement Python's context > manager protocol ( > https://docs.python.org/2/reference/datamodel.html#with-statement-context-managers > ). > > Basically, if a class implements __enter__ and __exit__ methods, it can be > used as the context manager in a `with` statement. When the block inside > the `with` statement begins, the context manager's .__enter__() method is > called, and when the block exits, the context manager's .__exit__() method > is called unconditionally (even if an exception occurs in the block). > > When using a Group node as a context manager, its .begin() method will be > called by .__enter__(), and .end() will be called by .__exit__(). Thus, > this is redundant: > > with group: > group.begin() > # Do something... > group.end() > > It's worth noting that Nuke currently always returns the current context > to the root node when a group context is exited, rather than to whatever > context it was in before the context was changed to the group, though this > is logged as a bug. > > Hope that helps. > > -Nathan > > > *From:* Justin GD <j.grosde...@gmail.com> > *Sent:* Tuesday, November 17, 2015 9:58 AM > *To:* Nuke Python discussion <nuke-python@support.thefoundry.co.uk> > *Subject:* Re: [Nuke-python] nuke.zoom and in group button > > Hi all, > > That's a good question; > I've been using the *with *statement as well with success. > > I'm curious of what is the best method. > > Cheers, > Justin > > 2015-11-17 17:24 GMT+00:00 Den Serras <denserras...@gmail.com>: > This leads to a slightly tangential discussion... I used to always use: > > with group: > (inner node stuff) > > which generally seemed to work; but so many people use begin() that now I > play it safe and do: > > with group: > group.begin() > (inner node stuff) > group.end() > > But perhaps someone can explain what the theoretical and functional > differences are between "with group" and "group.begin()", and whether by > combining them I'm causing even more problems... > > Thanks! > Den > > On Tue, Nov 17, 2015 at 1:29 AM, Johan Forsgren <j.a.forsg...@gmail.com> > wrote: > Root().begin() worked wonderfully, I had actually no idea that it existed > at all, thanks! > > > 2015-11-16 18:05 GMT+01:00 Mike Frank <michaeljfr...@gmail.com>: > nuke.Root().begin() > > > > _______________________________________________ > Nuke-python mailing list > Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > > > > _______________________________________________ > Nuke-python mailing list > Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > > > > ------------------------------ > _______________________________________________ > Nuke-python mailing list > Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > > > _______________________________________________ > Nuke-python mailing list > Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > >
_______________________________________________ Nuke-python mailing list Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python