← Back to team overview

dolfin team mailing list archive

dolfin.File and with statements

 

Hi,

To ensure proper closing of files in python I like to use:

with f as open('fileforwriting', 'w'):
  # write stuff to file

I tried doing the same with a dolfin.File(), but it does not seem to
have the requisite __exit__ method. E.g.:

---> 95 with dolfin.File(meshfilename) as mf : mf << mesh
     96 with dolfin.File(materialsfilename) as mf: mf << material_mesh_func
     97

AttributeError: __exit__

Is this a bug/lacking feature, or does the dolfin.File type
automatically flush/close files?

Thanks
Neilen


Follow ups