Living without static member functions
Richard Brodie
R.Brodie at rl.ac.uk
Mon Jan 24 06:06:03 EST 2000
There's a programming quirk of mine that I haven't seen elsewhere,
although probably well-known to some of you. Here's a rough outline
of the code:
class Milkman:
allMilkmen = {}
def __init__(self, name):
...
allMilkmen[name] = self
def find(self, name):
return(allMilkmen[name])
It's handy for debugging or garbage collecting like activities. Also
for distributed applications, where it's harder to keep object references
around.
Firstly, I'm curious if this is well-known, useful or boneheaded design
on my part.
Secondly, it doesn't work in Python, of course, because I need a
Milkman to find all the others (i.e. Milkman.find['Phil'] doesn't work).
I can do something similar by taking allMilkmen and find to module
scope; that seems kind of ugly, and worries me that I'm abusing the
language. Can I do better?
Thirdly, is there some neat way that I can find all members of a class
by inquiring of the Python internals?
Introspectively yours.
Richard Brodie.
More information about the Python-list
mailing list