@staticmethod<EOL><INDENT>def save_variables(filename, variables):<DEDENT>
ext = get_extension(filename).lower()<EOL>out_exts = {'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'}<EOL>output_file = filename<EOL>if not ext in out_exts:<EOL><INDENT>output_file = add_extension_if_needed(filename, '<STR_LIT>')<EOL>ext = get_extension(filename)<EOL><DEDENT>if ext == '<STR_LIT>' or ext == '<STR_LIT>':<EOL><INDENT>save_variables_to_shelve(output_file, variables)<EOL><DEDENT>elif ext == '<STR_LIT>':<EOL><INDENT>save_variables_to_mat(output_file, variables)<EOL><DEDENT>elif ext == '<STR_LIT>' or ext == '<STR_LIT>':<EOL><INDENT>from .hdf5 import save_variables_to_hdf5<EOL>save_variables_to_hdf5(output_file, variables)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(ext))<EOL><DEDENT>
Save given variables in a file.
        Valid extensions: '.pyshelf' or '.shelf' (Python shelve)
                          '.mat' (Matlab archive),
                          '.hdf5' or '.h5' (HDF5 file)

        Parameters
        ----------
        filename: str
            Output file path.

        variables: dict
            Dictionary varname -> variable

        Raises
        ------
        ValueError: if the extension of the filesname is not recognized.