Package esys :: Package escript :: Module util :: Class FileWriter
[hide private]
[frames] | no frames]

Class FileWriter

object --+
         |
        FileWriter

Interface to write data to a file. In essence this class wrappes the standart file object to write data that are global in MPI to a file. In fact, data are writen on the processor with MPI rank 0 only. It is recommended to use FileWriter rather than open in order to write code that is running with as well as with MPI. It is save to use open onder MPI to read data which are global under MPI.

Instance Methods [hide private]
 
__handelerror(self, errno, e, operation)
 
__init__(self, fn, append=False, createLocalFiles=False)
Opens a file of name fn for writing.
 
close(self)
Closes the file
 
flush(self)
Flush the internal I/O buffer.
 
write(self, txt)
Write string txt to file.
 
writelines(self, txts)
Write the list txt of strings to the file.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fn, append=False, createLocalFiles=False)
(Constructor)

 

Opens a file of name fn for writing. If running under MPI only the first processor with rank==0 will open the file and write to it. If createLocalFiles each individual processor will create a file where for any processor with rank>0 the file name is extended by its rank. This option is normally only used for debug purposes.

Parameters:
  • fn (str) - filename.
  • append (bool) - switches on the creation of local files.
  • createLocalFiles (bool) - switches on the creation of local files.
Overrides: object.__init__

write(self, txt)

 

Write string txt to file.

Parameters:
  • txt (str) - string txt to be written to file

writelines(self, txts)

 

Write the list txt of strings to the file.

Parameters:
  • txts (any iterable object producing strings) - sequense of strings to be written to file

Note: Note that newlines are not added. This method is equivalent to call write() for each string.