You can use itertools.product:

>>> for x,y,z in itertools.product(range(2), range(2), range(3)):
...     print x,y,z
... 
0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
0 1 2
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 1 2

If you've got numpy as a dependency already, numpy.ndindex will do the trick ...

>>> for x,y,z in np.ndindex(2,2,2):
...     print x,y,z
... 
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1