Python vs. Perl
aleaxit at yahoo.com
Fri May 25 16:06:12 CEST 2001
"Thomas Wouters" <thomas at xs4all.net> wrote in message
news:mailman.990779859.18387.python-list at python.org...
> if you want to keep statistics on how your functions are used, you don't
> have to change all your functions. You simply create a wrapper-class
> all your functions, that logs how and from where they are used, and then
> calls the original function. (Python classes can be callable, too.)
Yes, but what they do when you do call them is create an instance
object belonging to said class -- not very usable as a wrapper for
general-purpose functions. I suspect you mean to refer to the
fact that *instances* can be callable (and an instance *CAN* most
easily do the task you mention) rather than to that, equally true
but seemingly not very relevant in context, that classes are.
Wrapping all callables in (e.g.) a module so the wrappers count
how many times they're called is a suitable exercise for a Python
beginning to intermediate student -- the kind of thing somebody
already highly experienced in other languages will do like crazy
when he's been Pythoning for a month or so, because it's so easy
and fun it really goes to your head (unless your background is
in Lisp or thereabouts, I guess, since then the tricks may be old
hat to you... but even then, it may be fun to see how the approach
works without macros, without s-lists, etc, and still quite well).
> meant general-purpose/performance, not just 'more features'. You can stuff
> any hashable Python object in a Python hash, both as key and as value, and
True, but the value (as opposed to the key) doesn't even need to
be hashable, does it?
More information about the Python-list