class Singleton( object ): _instances = dict() def __new__(cls, *args, **kwargs): if cls not in cls._instances: cls._instances[cls] = object.__new__(cls, *args, **kwargs) return cls._instances[cls] class A( Singleton ): def __init__( self, x ): self.x = x a = A(1) print id(a) print id(a.x) b = A(2) print id(b) print id(b.x)
あーわかった。上書きされてるのか。