and it HAS to be part of the class, so you know what class object to pass
in...
But I think the OP was asking about @staticmethod -- which really is jsut
like a plain old stand alone function.
(not idea what "friend" is in C++)
So yes, any staticmthod could jstu be a stand alone functinin a module. But:
Other, more "pure" OO languages have satic methods because there is no such
ting as a stand alone function. That doesn't apply to Python, but
staticmethods allow you to put things that logically belong together
together, and also allow a cleaner namespace:
from a_module import A_Class
A_Class.a_staticmethod1()
A_Class.another_tatic_method()
....
so you only bring the one name into the current namespace -- for functions
that all have somethign to do with the class, it's a cleaner API.
the only functional difference I can think of is that as a staticmethod, it
can be overridden in a subclass.
There doesn't appear to be a PEP For this -- 'cause it dates back to Python
2.2 - too bad, it would be nice to see the justification. But it seemed to
go along with "new style" classes.
-CHB
···
On Thu, May 11, 2017 at 10:05 AM, Tim Roberts <timr@probo.com> wrote:
If a function can be called without the Le and instance, then what value
is their having it in the class at all?
This looks like a friend in C++, which just tears the OO walls apart.
It's not like "friend" at all. It's closer to a C++ static method. The
@classmethod is declared within the class, and has access to the class
variables.
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov