Class methods
Hughes, Chad O
chad.hughes at pnl.gov
Wed Oct 5 20:13:27 CEST 2005
Is there any way to create a class method? I can create a class
variable like this:
class Foo:
classVariable = None
def __init__(self, classVariable):
Foo.classVariable = classVariable
A = Foo('a')
B = Foo('b')
Print 'The class variable for A is "%s" and the class variable for B is
"%s"'%(a.classVariable,b.classVariable)
When you run this, you see the following:
The class variable for A is "b" and the class variable for B is "b"
This is what I expect. However, I wand to write a function that can be
called on a class directly. Lets say the name of the function is bar.
This function needs to be callable without an instance. The class will
be maintaining a queue, as a class variable, that all instances of that
class will use to place data in. When bar is called - perhaps by
Foo.bar() - bar will operate on the all of the data provided by its
instances.
Any ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051005/f343a127/attachment.html>
More information about the Python-list
mailing list