static methods
Robin Thomas
robin.thomas at starmedia.net
Sat Mar 24 13:11:43 EST 2001
At 04:38 PM 3/24/01 +0000, you wrote:
>On Fri, 23 Mar 2001 16:51:10 -0500 (EST), Clark C. Evans
><cce at clarkevans.com> wrote:
>
> >I was wondering if there is any rationale as to why
> >Python classes do not have static methods?
>
>What's a "static method?" I assume it's some C++ contrivance?
In the simplest sense (C++ and Java), a static method is reached through
the class, and not through instances of the class. Often used for factory
or conversion functions, or to provide a procedural interface when
instantiation would be a tedious formality. If there were a "static"
keyword in Python:
class Pickler:
def static loads(string):
return Pickler().loads(string)
def static dumps(object):
return Pickler().dumps(object)
def loads(self, string):
# the instance method
def dumps(self, object):
# the instance method
That it's called "static" is an artifact of C, I believe. In C, "static"
has been overexploited such that it has many different meanings in
different contexts that have nothing to do with being "static". Hideous
example: declaring a function as "static" in C means that it's invisible to
code outside of the source file and to all code following it in the same
file. :-0
--
Robin Thomas
Engineering
StarMedia Network, Inc.
robin.thomas at starmedia.net
More information about the Python-list
mailing list