callbacks in python

Ken Seehof kens at sightreader.com
Fri Jun 16 01:54:29 EDT 2000


Sure, that's one good way to do it.  It's particularly easy to do in python.

>>> class Eggs:
...     def __init__(self, spammer):
...         self.spammer = spammer
...     def OnSpam(self, a,b):
...         self.spammer(a,b)
...
>>> def SpamCallback(a,b):
...     print 'spam and ' + a + ' and spam and spam and ' + b
...
>>> e = Eggs(SpamCallback)
>>> e.OnSpam('green eggs', 'ham')
spam and green eggs and spam and spam and ham
>>>

Jonathan Epstein wrote:

> I'm working on my first Python project, and am encountering the issue of
> callbacks.  In particular, whenever my class undergoes a change which
> modifies its print representation, I would like to notify a callback
> routine which has been specified by the user of the class.  This
> callback routine would usually be some sort of GUI.
>
> Is this the right way to do things in python?  I read a reference in
> _Python Programming on Win32_ which seemed to suggest that this was not
> the right way to do things, but I am not sure.
>
> Thanks in advance for any help, especially including any pointers to
> examples...
>
> - Jonathan

--
Ken Seehof
kens at sightreader.com
starship.python.net/crew/seehof
Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kens.vcf
Type: text/x-vcard
Size: 343 bytes
Desc: Card for Ken Seehof
URL: <http://mail.python.org/pipermail/python-list/attachments/20000615/a68eef03/attachment.vcf>


More information about the Python-list mailing list