_Re: singleton (newbie)

Neil Zanella nzanella at cs.mun.ca
Thu Aug 19 00:13:42 CEST 2004


Hello,

Is this the correct way to code multi-instance singleton in Python?
It seems to do the trick for me but I appreciate any criticism as I
am somewhat new to Python.

Thanks,

Neil

#!/usr/bin/python

class B:
  x = 0
  y = 1
  def foo(): print B.x
  foo = staticmethod(foo)
  def bar(): print B.y; B.y += 1
  bar = staticmethod(bar)

if __name__ == "__main__":
  B.foo()
  B.bar()
  B.foo()
  B.bar()
  B.bar()



More information about the Python-list mailing list