type annotation vs working code
Barry
barry at barrys-emacs.org
Sun Oct 1 18:08:52 EDT 2023
> On 1 Oct 2023, at 19:36, Richard Damon via Python-list <python-list at 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
More information about the Python-list
mailing list