What better way to get around the “static variables” in Python?

后端 未结 3 528
情歌与酒
情歌与酒 2021-01-28 01:35

It seems that in Python, to declare a variable in a class, it is static (keeps its value in the next instances). What better way to get around this problem?

clas         


        
3条回答
  •  鱼传尺愫
    2021-01-28 02:32

    You maybe want to change the class attribute:

    class Foo():
        number = 0
        def set(self):
            Foo.number = 1
    

    instead of overriding it!

提交回复
热议问题