write_data

sherpa.io.write_data(filename: str, dataset: Data, fields: Sequence[str] | None = None, sep: str = ' ', comment: str = '#', clobber: bool = False, linebreak: str = '\n', format: str = '%g') None[source] [edit on github]

Write out a dataset as an ASCII file.

Parameters:
filenamestr

The name of the file to write the array to.

dataset

The data object to write out.

fieldsarray_like of str

The column names (should match the size of args if given). Any unknown columns are skipped. If not given then the field names from the data set will be used (for those columns which contain data).

sepstr, optional

The separator character. The default is ' '.

commentstr, optional

The comment character. The default is '#'. This is used to write out the column names (after converting to upper case) before the data.

clobberbool, optional

If filename is not None, then this flag controls whether an existing file can be overwritten (True) or if it raises an exception (False, the default setting).

linebreakstr, optional

Indicate a new line. The default is '\n'.

formatstr, optional

The format used to write out the numeric values. The default is '%g%'.

Raises:
sherpa.utils.err.IOErr

If filename already exists and clobber is False or if there is no data to write.

Examples

Write the x and y arrays to the file ‘src.dat’:

>>> write_data('src.dat', dat)