[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 13:51:03 CET 2009

I am posting this question to two Python forums: Tutor and Python(x,y).

In the case of Tutor [1], I think it's the right place to ask questions for
a newbie like me.

In the case of Python(x,y) Discussion Group [2], I am posting also because I
think I am addressing a specific group of Python users that probably
previously dealed with the same problems I do now. Anyway, let me know if
it's a good idea to keep on doing this in the future.

This question is about how to define classes or objects (or data structures)
I need to use, and how to do it in an efficient way.

I want to define an object or data structure called "Problem".

That "problem" has to contain, somehow, a property or element called
"function" which, in fact, I would like it to be a function, or a "pointer"
to a function.

For example, if  "prob"  is a "Problem" object, I would like to be able to
do something like this:

# call the function in prob, and store the result in "x" :

x = prob.function( arguments/variables required by the function )

Does it makes any sense? Which would it be the right (meaning efficient but
still object-oriented-programming-compliant) way to do it?

I mean, if I store "a whole function" within each "Problem" object (assuming
it can be done in Python), each Problem object would be consuming lot of
memory (wouldn't it?). Maybe it would be better just to store a kind of
"pointer" to the function within the "problem" object, so the object would
be "lighter". The function would be then defined outside the object, as

Can you give me some hint about this?

By the way, I have another related question. In C you can pass arguments to
a function by value or by reference. Is there any equivalence in Python to
that approach? How is the usual way to pass function arguments in Python?

I guess I'll discover many of this things by my own when "playing arround"
with Python, but some orientation will be welcomed.

[1] http://mail.python.org/mailman/listinfo/tutor

[2] http://groups.google.es/group/pythonxy

Thank you very much in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090116/c2c5f4db/attachment.htm>

More information about the Tutor mailing list