🎯 ANOTHER PYTHON CHALLENGE: Can Your Code Feel Things?
Tired of dull exceptions? Let’s turn every error into art.
🧪 Your mission (should you accept it):
Write a Python function that turns exceptions into haikus. Yes—actual 5–7–5 haikus, delivered when your code breaks.
✅ Bonus points if:
Each exception type has its own poetic flavor (ValueError? Existential crisis.)
It’s short, beautiful, and reusable—maybe even a decorator 👀
You include at least one haiku that references the void 🌌
💡Why? Because code doesn’t always have to be cold and clinical. Sometimes it can cry softly in structured verse.
📬 Post your favorite haiku + your code snippet in the comments. Let’s make debugging… poetic.
#Python #DevChallenge #CreativeCoding #WeirdCodeWednesday #HaikuDrivenDevelopment
Here is the code, can you do better:
import random
def haiku_on_exception(func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
haikus = {
"ValueError": [
"Digits overflow,\nMistakes dance in the silence—\nThe loop cries alone.",
"Miscalculated,\nThe sum drifted into mist—\nAll zeros now fade."
],
"TypeError": [
"Strings don't greet numbers,\nThey speak different languages—\nHarmony denied.",
"A type mismatch screams,\nSyntax stumbles through the fog—\nLogic breaks apart."
],
"KeyError": [
"Lost key in the void,\nMemory no longer speaks—\nWas it ever there?",
"You reached for the name,\nBut silence answered instead—\nMap of ghosts remains."
],
"default": [
"Code cracked like dry leaves,\nAutumn came to my logic—\nTry again, kind soul.",
"Exceptions arrive,\nNot with fire, but with sighs—\nStill, we build again."
]
}
error_type = type(e).__name__
haiku = random.choice(haikus.get(error_type, haikus["default"]))
print(f"\n🧨 Exception: {error_type}\n📜 {haiku}\n")
raise
return wrapper