Counting instances of a class?

后端 未结 7 1514
失恋的感觉
失恋的感觉 2020-11-29 04:19

I\'ve been cleaning up some code from a module I\'m extending and I can\'t seem to find a way to Pythonify this code:

global_next_id = 1

class Obj:
  def __         


        
7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 04:38

    class Obj:
        global_next_id =0
        def __init__(self):
            Obj.global_next_id += 1
    
    my_obj = Obj()
    print(Obj.global_next_id)
    

提交回复
热议问题