← Back to team overview

dolfin team mailing list archive

Re: dolfin.File and with statements

 

On Mon, Jul 18, 2011 at 05:51:56PM +0200, Neilen Marais wrote:
> 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?

Yes, DOLFIN Files are automatically closed after each call to <<.

--
Anders


References