@staticclass

| | Add comment | Trackbacks (0) | Next | Previous

decorator to make all objects in a class static methods.

i haven't tested this

it probably won't work on python 2.6. for some reason 2.6 doesn't seem to like .im_func
i should probably just use staticmethod() anyway instead of using im_func.

def staticclass(cls): #to be used as a decorator
  for attr in dir(cls):
    obj = getattr(cls, attr)
    if iscallable(obj) and not attr.startswith("__"):
      setattr(cls, attr, obj.im_func)
  return cls

Comments

Add comment
 authimage