"static" class functions?

Neil mac4-devnull at theory.org
Tue May 22 18:08:02 EDT 2001


I am interested in having a function associated with a class that can be
run without an instance of the class.

For example:

class Foo:
    __val = 5
    def printPrivate():
        print Foo.__val

I have a class like the above, and when I import the class, it doesn't
complain.  When I call the function though, it complains that the
function is unbounded.  When I create an instance of the class and try it
that way, it complains that no argunets were expected in the function.

Does this mean that ALL functions defined for Foo must take the self
perameter?  What if I want to set some value that all instances of the
class use, but I don't want an instance of the class to set the value?

Thanks,  Neil Macneale

PS- replys be email should go to my reply address, but remove the "-devnull"



More information about the Python-list mailing list