> > > and wouldn't bother with staticmethods at all. How often do you > > > actually need a staticmethod in particular and *not* a classmethod? > > > > It's quite useful to be able to develop, essentially stateless, static > > method utility libraries that dont need to be class based. Why create > > I'm not sure I understand. Why not make them module-level functions? Namespaces my friend, namespaces (I don't know if other people use this, but I have on occasion). #example.py class functions_a: def foo(inp1, inp2) [staticmethod]: #do something #more functions that do something class functions_b: def foo(inp1, inp2) [staticmethod]: #do something slightly different #more functions that do something different #end example.py We can use the classes as mini namespaces, and only need to import and distribute a single module. With class decorators (which seem to be in favor right now), we can go even a step farther with the following (which is another reason why class decorators are a good idea)... def make_all_static(cls): for i,j in cls.__dict__.iteritems(): if isinstance(j, instancemethod) cls.__dict__[i] = staticmethod(j) class functions_c [make_all_static]: def foo(inp1, inp2): #do something a bit more different #more functions that do something a bit more different Once again, you can use classes as namespaces in a single module. - Josiah
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4