[Tutor] "Pointer" to a function? Storing a function as an object property? Passing arguments by value/by reference?
Vicent
vginer at gmail.com
Fri Jan 16 16:28:34 CET 2009
On Fri, Jan 16, 2009 at 14:56, greg whittier <greg at thewhittiers.com> wrote:
>
> In python, the name of a function is just a pointer to it. Try this
>
> >>> def foo():
> print "Hi!"
>
>
> >>> class Problem:
> def __init__(self,fun):
> self.fun = fun
>
>
> >>> p1 = Problem(foo)
> >>> p2 = Problem(foo)
> >>> foo
> <function foo at 0x012C52B0>
> >>> p1.fun
> <function foo at 0x012C52B0>
> >>> p2.fun
> <function foo at 0x012C52B0>
> >>> p1.fun == p2.fun
> True
> >>>
>
Wow!!! I thought that the question was simple but I was afraid that the
answer was going to be too complex.
But I see that it actually works like I thought it should!!! It's extremely
simple and intuitive, IMHO.
Thank you to all for your precise and clear answers. I've learned a lot, and
specially appreciate the links that Kent provided.
I hope I can contribute to this forum in the future.
--
Vicent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090116/be721177/attachment.htm>
More information about the Tutor
mailing list