小编use*_*870的帖子

如何防止__init__?蟒蛇

这是我的代码:

class Game_Events(object):
    def __init__(self):
        print "Done"

    def thing(self):
        print "thing"

    def test(self):
        print "test"
        GE = Game_Events()
        GE.thing()

GE = Game_Events()
GE.test()
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到:

Done
test
Done
thing
Run Code Online (Sandbox Code Playgroud)

__init__当我打电话给GE.thing()时,这意味着它又跑了.但我不知道它在开始时只运行一次然后再也不会运行.

我怎样才能做到这一点?

python function

-5
推荐指数
1
解决办法
126
查看次数

标签 统计

function ×1

python ×1