Try
from dolfin import *
mesh = UnitSquareMesh(42, 42)
family = 'Lagrange'
degree = 1
shape = 4*(mesh.geometry().dim(),)
V = TensorFunctionSpace(mesh, family, degree, shape=shape)
But I warn you that working with Function
s being tensors of rank>1 isn't much tested and probably not well-handled in DOLFIN (and UFL) e.g. because of issue 242. So you may consider flattening your space like
V = VectorFunctionSpace(mesh, family, degree, dim=4*mesh.geometry().dim())
and then handle component indices by yourself.