Only instances of new-style classes can have properties. You can make Python believe such an instance is a module by stashing it in sys.modules[thename] = theinstance
. So, for example, your m.py module file could be:
import sys
class _M(object):
def __init__(self):
self.c = 0
def afunction(self):
self.c += 1
return self.c
y = property(afunction)
sys.modules[__name__] = _M()
Edited: removed an implicit dependency on globals (had nothing to do with the point of the example but did confuse things by making the original code fail!).