function pointers
Remco Gerlich
scarblac at pino.selwerd.nl
Thu Apr 26 08:19:39 EDT 2001
Brandon J. Van Every <vanevery at 3DProgrammer.com> wrote in comp.lang.python:
> Please pardon my ignorant questions. I'm just trying to grok Python
> efficiently as a complete beginner, without having to search endlessly in
> every page of TFM.
>
> I get the feeling that Python doesn't have anything resembling a function
> pointer? i.e. no way to call a specific function according to the value a
> variable is set to? In fact, I get the feeling it doesn't have pointers of
> any sort at all?
It's the other way around. *Everything* is a pointer.
def whee(x):
print "My argument was:", x
'whee' is now a reference (pointer) to the function we just created.
We can pass it to itself, for instance:
>>> whee(whee)
My argument was: <function whee at 8071750>
Every variable is just a reference to an object somewhere.
And functions are just objects, just like lists, integers, and everything.
--
Remco Gerlich
More information about the Python-list
mailing list