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

April 14, 2013

Python Tricks

if this is a short post, check back some other time.


Python 3

These are more elaborations on, and examples of, Idiomatic Python. They are meant to be self contained. I'll update this post with certain frequency.

enumerate

list comprehensions

with an if statement..

map

useful for doing something with each member of an iterable, like converting every member into a float. To use the result of map(a, b) as a list you must do list(map(a,b).

operations on and with lists

Flatten a list

default function argments

use vars() to read the variables available in the local scope.

checking for Truth

I see quite a bit of verbose if-statements, here's a reminder of what\s possible. and this would print the same list

any() and all()

if any of the following strings are present in the larger list, return a True or return True only when all items are present.