pyyeti.guitools.read_text_file

pyyeti.guitools.read_text_file(rdfunc)[source]

Decorator that processes the file argument for text reading

Defaults to UTF-8 encoding, but if rdfunc has keyword argument for “encoding”, that will be used instead.

Parameters:

rdfunc (function) – Function that reads text from 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 the name of a directory or None; in these cases, a GUI is opened for file selection. For example, see pyyeti.nastran.bulk.rdgrids().

Returns:

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

Examples

>>> from pyyeti.guitools import read_text_file, write_text_file
>>> from io import StringIO
>>> @read_text_file
... def doread(f):
...     return f.readline()
>>> @write_text_file
... def dowrite(f, string, number):
...     f.write(f'{string} = {number:.3f}\n')
>>> with StringIO() as f:
...     dowrite(f, 'param', number=45.3)
...     _ = f.seek(0, 0)
...     s = doread(f)
>>> s
'param = 45.300\n'