我有以下 python 类:
class Coordinates:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
class Properties:
def __init__(self, w, h, d):
self.w = w
self.h = h
self.d = d
class Objects(Properties, Coordinates):
def __init__(self, x, y, z, w, h, d):
Coordinates.__init__(self, x, y, z)
Properties.__init__(self, w, h, d)
我希望每次在 main 中调用该类时都有一个增量的对象类唯一 ID。该 ID 在创建类实例时自动生成。
我想过使用该功能id()
但只有在创建对象时才有效。
a = Objects(1, 2, 3, 4, 5, 6)
b = Objects(1, 2, 3, 4, 5, 6)
print (id(a),id(b)) #(2400452, 24982704)