Person Example

Simple class using atom and static observers.


To see this example in action, download it from person and run:

$ python

Example Atom Code

# --------------------------------------------------------------------------------------
# Copyright (c) 2013-2022, Nucleic Development Team.
# Distributed under the terms of the Modified BSD License.
# The full license is in the file LICENSE, distributed with this software.
# --------------------------------------------------------------------------------------
"""Simple class using atom and static observers.

from atom.api import Atom, Bool, ChangeDict, Range, Str, observe

class Person(Atom):
    """A simple class representing a person object."""

    last_name = Str()

    first_name = Str()

    age = Range(low=0)

    debug = Bool(False)

    def debug_print(self, change: ChangeDict) -> None:
        """Prints out a debug message whenever the person's age changes."""
        if self.debug:
            templ = "{first} {last} is {age} years old."
            s = templ.format(first=self.first_name, last=self.last_name, age=self.age)

if __name__ == "__main__":
    john = Person(first_name="John", last_name="Doe", age=42)
    john.debug = True
    john.age = 43