""" Educational anti-example. This program intentionally violates several Zen of Python principles to demonstrate classes, threads, exceptions, and the __main__ idiom, while doing nothing more than printing "Hello, world!". """ import threading # filename: hello_world_pep20_violation.py class Hello: """ A deliberately over-engineered Hello World example. """ def __init__(self, message="Hello, world!"): self.message = message def launch_greetings(self): # A daemon thread is considered non-essential. # If the main program ends, Python does not wait for daemon threads. # They may be stopped before completing their work. # # thread = threading.Thread(target=self.greetings, daemon=True) # Here we create a regular thread instead. # Python will keep the program alive until this thread has finished. # Avoid: # thread = threading.Thread(target=self.greetings, daemon=True) thread = threading.Thread(target=self.greetings) # Start the thread. # This runs self.greetings() separately from the main program flow. thread.start() # Wait until the thread has finished. # Without join(), the main program could continue immediately. thread.join() def greetings(self): try: print(f"\n{self.message}\n") # This is intentionally broad for demonstration. # In real code, catch specific exceptions whenever possible. except Exception: print("\nYou cannot save the world so easily!") finally: print(f"You know how to print {self.message} in a console! Congratulations Champion!") print("\t- I just wanted to print Hello World,\n\nbut then I accidentally revised half of Python.") print('\nOf course, you could simply use print("Hello, world!")\nbut here you will learn\n\t- classes\n\t- threads\n\t- try\n\t- except\n\t- finally\n\t- exceptions\n\t- f-strings\n\t- tabs and line breaks in strings...\n') print("So yes, this is Hello World with unnecessary engineering.") print("So this will never be approved in a PEP!") print(f"© Nicolas Pirson 03/07/2026 (my birthday) 😉\nCheck my website at https://pirson.me") if __name__ == "__main__": hello = Hello() hello.launch_greetings() # Without this line, the console may close immediately # when the script is launched by double-clicking the file. # Avoid time.sleep(n) here: it waits for a fixed duration, # while input() waits until the user is ready to exit. input("\nPress Enter to exit...")