> On 1 Oct 2023, at 19:36, Richard Damon via Python-list > <python-list@python.org> wrote: > > Perhaps a better method would be rather than just using the name and catching > the exception, use a real already_initialized flag (set to True when you > initialize), and look it up with getattr() with a default value of False. I would use a class variable not an instance variable. class OnlyOne: sole_instance = None def __init__(self): assert OnlyOne.sole_instance is None OnlyOne.sole_instance = self Barry -- https://mail.python.org/mailman/listinfo/python-list
- type annotation vs working code Karsten Hilbert via Python-list
- Re: type annotation vs working code Mats Wichmann via Python-list
- Re: type annotation vs working code dn via Python-list
- Re: type annotation vs working co... Karsten Hilbert via Python-list
- Re: type annotation vs workin... dn via Python-list
- Re: type annotation vs wo... Karsten Hilbert via Python-list
- Re: type annotation ... Chris Angelico via Python-list
- Re: type annotation ... Richard Damon via Python-list
- Re: type annotat... Barry via Python-list
- Re: type ann... Chris Angelico via Python-list
- Re: type annotation ... dn via Python-list
- Re: type annotat... Chris Angelico via Python-list
- Re: type ann... dn via Python-list
- Re: type annotat... Greg Ewing via Python-list
- Re: type ann... Chris Angelico via Python-list
- Re: type annotat... Karsten Hilbert via Python-list