Re: [Pyobjc-dev] extending a class with dynamically defined methods
Brought to you by:
ronaldoussoren
From: <yt...@em...> - 2005-06-02 10:31:25
|
On Thu, 2 Jun 2005 07:51:19 +0200, "Ronald Oussoren" <ron...@ma...> said: > > On 1-jun-2005, at 13:52, yt...@em... wrote: > > > I've written a Quicksilver plug-in using PyObjC that provides > > OnMyCommand commands (these are user defined) as actions. > > > > In order to implement this, I extended a class with methods defined > > dynamically. For each OnMyCommand command, I used exec twice -- > > once to > > define a function and once to convert the function into a method for a > > class. > > I've not been following this discussion very closely, hence the late > answer. > > You don't have to exec to convert a function into a method, using > setattr > also works: > > class SuperDuperClass (NSObject): # or plain python > pass > > myfunc = BuildFunction("bla bla") > > SuperDuperClass.myfunc = myfunc Thanks for this suggestion. I tested this out using setattr() directly -- so I could specify the name of the function at runtime -- and it seems to be working :-) -- yt...@em... -- http://www.fastmail.fm - A fast, anti-spam email service. |