Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

October 04, 2012

Decorators Python

Despite the many hours I spend writing python code, it's not often that I come across concepts that don't make sense. But it does happen, and one of those concepts (patterns?) is the decorator.

Blender scripting uses a class method (@classmethod) sometimes, so the notation isn't alien. Stackoverflow has an explanation that managed to finally break it down for me. Now I know from experience that with every new concept that comes into the repertoire it's likely i'll use and abuse it for a while until I can judge more sanely when to use the pattern, and when it gets in the way of readability.

I will avoid explaining here how this works, read the stackoverflow article. But as usual here is a snippet that sums up what I managed to get from it. ..Perhaps come back to this post with more blender related reasons to use a decorator. Or if you know of a use that you would like to showcase, let me know below.

here's another: or a more bpy related version:

No comments:

Post a Comment

Please use Blender.StackExchange.com for python scripting questions unrelated to this post.