Posts Tagged ‘Gamedev’

Decorators in Python

I know this might not be quite as worthwhile as my other material (I do not deny that even THAT isn’t very worthwhile), but I’ve stumbled upon something so ingenious that I have to post about it. Actually, it isn’t as amazing as it sounds. It’s just somebody that explained Python decorators on Stack Overflow. And that, he did quite well. I’m writing a little text adventure in Python for fun (and for learning purposes). A simple text adventure allows me to step back from all the API junk and programming techniques I might learn or have to use elsewhere and instead focus on getting my code right and researching new ways. I’m also reading an intrudoctory paper on event-driven programming by Stephen Ferg that has opened my eyes (I’m practically reborn).

Anyway, decorators! Scroll down a bit for the epic explanation. In my case,  I wanted to have a simple prompt function which then passes its result to the prompt method for the room/level. Not so easy if you call the prompt function in main(). Hmm…

http://pastebin.com/0JXQhmNY

Thank you e-satis!

PS. I can’t properly paste Python code. Stupid Wordpress…

Tags: , , , , ,

No Comments



SetPageWidth