sfepy.base.ioutils module

class sfepy.base.ioutils.InDir(filename)[source]

Store the directory name a file is in, and prepend this name to other files.

Examples

>>> indir = InDir('output/file1')
>>> print indir('file2')
sfepy.base.ioutils.edit_filename(filename, prefix='', suffix='', new_ext=None)[source]

Edit a file name by add a prefix, inserting a suffix in front of a file name extension or replacing the extension.

Parameters:

filename : str

The file name.

prefix : str

The prefix to be added.

suffix : str

The suffix to be inserted.

new_ext : str, optional

If not None, it replaces the original file name extension.

Returns:

new_filename : str

The new file name.

sfepy.base.ioutils.ensure_path(filename)[source]

Check if path to filename exists and if not, create the necessary intermediate directories.

sfepy.base.ioutils.get_print_info(n_step, fill=None)[source]

Returns the max. number of digits in range(n_step) and the corresponding format string.

Examples:

>>> get_print_info(11)
(2, '%2d')
>>> get_print_info(8)
(1, '%1d')
>>> get_print_info(100)
(2, '%2d')
>>> get_print_info(101)
(3, '%3d')
>>> get_print_info(101, fill='0')
(3, '%03d')
sfepy.base.ioutils.get_trunk(filename)[source]
sfepy.base.ioutils.locate_files(pattern, root_dir='.')[source]

Locate all files matching fiven filename pattern in and below supplied root directory.

sfepy.base.ioutils.read_array(fd, n_row, n_col, dtype)[source]

Read a NumPy array of shape (n_row, n_col) from the given file object and cast it to type dtype. If n_col is None, determine the number of columns automatically.

sfepy.base.ioutils.read_dict_hdf5(filename, level=0, group=None, fd=None)[source]
sfepy.base.ioutils.read_list(fd, n_item, dtype)[source]
sfepy.base.ioutils.read_sparse_matrix_hdf5(filename, output_format=None)[source]
sfepy.base.ioutils.read_token(fd)[source]

Read a single token (sequence of non-whitespace characters) from the given file object.

Notes

Consumes the first whitespace character after the token.

sfepy.base.ioutils.remove_files(root_dir)[source]

Remove all files and directories in supplied root directory.

sfepy.base.ioutils.skip_read_line(fd, no_eof=False)[source]

Read the first non-empty line (if any) from the given file object. Return an empty string at EOF, if no_eof is False. If it is True, raise the EOFError instead.

sfepy.base.ioutils.write_dict_hdf5(filename, adict, level=0, group=None, fd=None)[source]
sfepy.base.ioutils.write_sparse_matrix_hdf5(filename, mtx, name='a sparse matrix')[source]

Assume CSR/CSC.