Make 'def' and 'class' usable within expressions

Joe Mason joe at notcharles.ca
Fri Mar 26 19:58:00 EST 2004


In article <mailman.449.1080312877.742.python-list at python.org>, Shane Hathaway wrote:
>> I would write a class.
>> 
>> obj.add_listener(class):
>>     def on_success(self):
>>         print 'yay!'
>>     def on_error(self):
>>         print 'ohh.'
> 
> Oops, that's not quite correct.  It should pass an instance rather than 
> a class.
> 
> obj.add_listener((class)()):
>      def on_success(self):
>          print 'yay!'
>      def on_error(self):
>          print 'ohh.'
> 
> That's not pretty. :-(

Use Prothon, and that ugliness goes away!

(Sorry to thread-jack, I just thought that was a good example of where
prototypes are nice.)

Joe



More information about the Python-list mailing list