Possible to Combine Class with Executable Script?

37 views Asked by At

Is it possible to combine a class along with an executable script in a single file?

i.e. see the code below:

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

  def main():
    try:
        execute_app()
    finally:
        handle_cleanup()

if __name__=='__main__':
    Person.main()

and, if it is possible, what are its merits?

0

There are 0 answers