class SingletonLoader(object):
cachedStates = {}
def __new__(cls, key, loadFunc):
print "SingletonLoader.new: cls = %s, key = %s, loadFunc = %s" % (cls, key, loadFunc)
if key not in cls.cachedStates:
plugin.msg("New key %s, invoking loader function %s" % (key, loadFunc))
cls.cachedStates[key] = loadFunc()
plugin.msg("Cached %s under key %s" % (key, cls.cachedStates[key]))
return super(SingletonLoader, cls).__new__(cls, key, loadFunc)
def __init__(self, key, loadFunc):
# Set members from the cached state matching the key.
self.__dict__ = self.__class__.cachedStates[key]
Обратная линия супер (SingletonLoad ...... бросает ошибку, упомянутую в названии.объект .__ новый __() не принимает parametrs
Любая идея, почему.
Вы можете найти это полезным: http://stackoverflow.com/questions/674304/pythons-use-of-new-and-init –