Do rather
from dolfin import *
mesh = UnitSquareMesh(2, 2)
a = MeshFunction('size_t', mesh, 2)
a.set_all(1)
File("mesh.xml") << mesh
File("mesh_func.xml") << a
as MeshData.create_mesh_function()
will be removed in next release.
To access stored data
mesh = Mesh('mesh.xml')
a = MeshFunction('size_t', mesh, 'mesh_func.xml')
This is more stable solution than storing markers within mesh.