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...

June 26, 2014

fun with dicts

A Python self invoking dict func. In the example below, whatever `self.mode`, it will call the two named functions if the input to `.get()` is in the dict keys(), else the lambda: None :)
{
    "input": self.input_mode,
    "output": self.output_mode
}.get(self.mode, lambda: None)()

>>> def g(): print("hooo")
...
>>> g()
hooo
>>> def h(): print("boo")
...
>>> {'i': g, 'k': h}.get('i', lambda: None)()
hooo
>>> {'i': g, 'k': h}.get('f', lambda: None)()
>>>
view raw brainz.py hosted with ❤ by GitHub