singleton ... again
Asaf Las
roegltd at gmail.com
Wed Feb 12 20:38:55 EST 2014
On Wednesday, February 12, 2014 11:57:02 PM UTC+2, Gregory Ewing wrote:
>
> If you want to hide the distinction between using
> call syntax and just accessing a global, then
> export a function that returns the global instance.
>
> That function can even lazily create the instance
> the first time it's called. That's a pattern that
> *is* useful, and I've often used in Python and
> other languages.
> E.g.
> _the_whatsit = None
> def get_whatsit():
> if _the_whatsit is None:
> _the_whatsit = Whatsit()
> return _the_whatsit
> Greg
Gregory Ewing and Michael Torrie, yes you are both right, that is how things
are done in standard Python library. But i am not restricting myself to that.
Thanks
/Asaf
More information about the Python-list
mailing list