why is there no class (static) methods in Python ?

D-Man dsh8290 at rit.edu
Mon Jun 18 15:45:55 EDT 2001


On Mon, Jun 18, 2001 at 12:21:53PM -0700, James_Althoff at i2.com wrote:
<...>
| I notice that yourModule.yourFunction1
| is exactly what I want, but I need to override yourModule.yourFunction2 in
| order to adapt it for myModule.MyClass.  How can I do this (preferably
| WITHOUT resorting to "black magic" and whilst preserving
| "thread-safeness")?

#### myModule.py

import yourModule

myFunction1 = yourModule.yourFunction1

def myFunction2( ) :
    pass

| I am stuck -- because module functions are NOT methods (in the sense that
| they are not associated with an instance) and hence do not participate in a
| "method lookup/override" mechanism.  So if I define my own

As Alex Martelli has demonstrated a few times, you can substitute a
class instance that implements __setattr__ and __getattr__ in place of
the module object in sys.modules.

| So true class methods -- methods invoked on class objects with inheritance
| and override (a la Smalltalk) -- are good -- and far better than module
| functions acting as a poor man's substitute therein -- mainly if you
| consider code extensibility and reuse a good thing.

Maybe the new meta class stuff will help with this?  (I don't know)

-D





More information about the Python-list mailing list