pyyeti.guitools.write_text_file

pyyeti.guitools.write_text_file(wtfunc)[source]

Decorator that processes the file argument for writing

Parameters:

wtfunc (function) – Function that writes text to a file. The first argument to that function is a file argument. The file argument can be the name of a file, or a file_like object as returned by open() or io.StringIO(). It can also be input as the integer 1 to write to stdout (or use sys.stdout). Finally, it can also be the name of a directory or None; in these cases, a GUI is opened for file selection. To write to a string, import io and set f = io.StringIO(); afterwards, retrieve string by f.getvalue(). For example, see pyyeti.nastran.bulk.wtgrids().

Returns:

function – Function that processes the file argument before calling wtfunc.

See also

read_text_file()

Examples

>>> from pyyeti.guitools import write_text_file
>>> @write_text_file
... def dowrite(f, string, number):
...     f.write(f'{string} = {number:.3f}\n')
>>> dowrite(1, 'param', number=45.3)
param = 45.300