We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Inconsistent exceptions raised by scipy.io.loadmat
Depending on whether loadmat is passed a non-existent filename with or without the ".mat" extension, the exception raised chages from IOError to FileNotFoundError.  I believe an easy patch would be to simply change `scipy.io.matlab.mio._open_file` to re-raise rather than raise `IOError(e)`.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scipy/io/matlab/mio.py`
Content:
```
1 """
2 Module for reading and writing matlab (TM) .mat files
3 """
4 # Authors: Travis Oliphant, Matthew Brett
5 
6 from __future__ import division, print_function, absolute_import
7 
8 import numpy as np
9 
10 from scipy.lib.six import string_types
11 
12 from .miobase import get_matfile_version, docfiller
13 from .mio4 import MatFile4Reader, MatFile4Writer
14 from .mio5 import MatFile5Reader, MatFile5Writer
15 
16 __all__ = ['mat_reader_factory', 'loadmat', 'savemat', 'whosmat']
17 
18 
19 def _open_file(file_like, appendmat):
20     ''' Open `file_like` and return as file-like object '''
21     if isinstance(file_like, string_types):
22         try:
23             return open(file_like, 'rb')
24         except IOError as e:
25             if appendmat and not file_like.endswith('.mat'):
26                 file_like += '.mat'
27                 return open(file_like, 'rb')
28             raise IOError(e)
29     # not a string - maybe file-like object
30     try:
31         file_like.read(0)
32     except AttributeError:
33         raise IOError('Reader needs file name or open file-like object')
34     return file_like
35 
36 
37 @docfiller
38 def mat_reader_factory(file_name, appendmat=True, **kwargs):
39     """Create reader for matlab .mat format files
40 
41     Parameters
42     ----------
43     %(file_arg)s
44     %(append_arg)s
45     %(load_args)s
46     %(struct_arg)s
47 
48     Returns
49     -------
50     matreader : MatFileReader object
51        Initialized instance of MatFileReader class matching the mat file
52        type detected in `filename`.
53     """
54     byte_stream = _open_file(file_name, appendmat)
55     mjv, mnv = get_matfile_version(byte_stream)
56     if mjv == 0:
57         return MatFile4Reader(byte_stream, **kwargs)
58     elif mjv == 1:
59         return MatFile5Reader(byte_stream, **kwargs)
60     elif mjv == 2:
61         raise NotImplementedError('Please use HDF reader for matlab v7.3 files')
62     else:
63         raise TypeError('Did not recognize version %s' % mjv)
64 
65 
66 @docfiller
67 def loadmat(file_name, mdict=None, appendmat=True, **kwargs):
68     """
69     Load MATLAB file
70 
71     Parameters
72     ----------
73     file_name : str
74        Name of the mat file (do not need .mat extension if
75        appendmat==True) Can also pass open file-like object.
76     m_dict : dict, optional
77         Dictionary in which to insert matfile variables.
78     appendmat : bool, optional
79        True to append the .mat extension to the end of the given
80        filename, if not already present.
81     byte_order : str or None, optional
82        None by default, implying byte order guessed from mat
83        file. Otherwise can be one of ('native', '=', 'little', '<',
84        'BIG', '>').
85     mat_dtype : bool, optional
86        If True, return arrays in same dtype as would be loaded into
87        MATLAB (instead of the dtype with which they are saved).
88     squeeze_me : bool, optional
89        Whether to squeeze unit matrix dimensions or not.
90     chars_as_strings : bool, optional
91        Whether to convert char arrays to string arrays.
92     matlab_compatible : bool, optional
93        Returns matrices as would be loaded by MATLAB (implies
94        squeeze_me=False, chars_as_strings=False, mat_dtype=True,
95        struct_as_record=True).
96     struct_as_record : bool, optional
97        Whether to load MATLAB structs as numpy record arrays, or as
98        old-style numpy arrays with dtype=object.  Setting this flag to
99        False replicates the behavior of scipy version 0.7.x (returning
100        numpy object arrays).  The default setting is True, because it
101        allows easier round-trip load and save of MATLAB files.
102     verify_compressed_data_integrity : bool, optional
103         Whether the length of compressed sequences in the MATLAB file
104         should be checked, to ensure that they are not longer than we expect.
105         It is advisable to enable this (the default) because overlong
106         compressed sequences in MATLAB files generally indicate that the
107         files have experienced some sort of corruption.
108     variable_names : None or sequence
109         If None (the default) - read all variables in file. Otherwise
110         `variable_names` should be a sequence of strings, giving names of the
111         matlab variables to read from the file.  The reader will skip any
112         variable with a name not in this sequence, possibly saving some read
113         processing.
114 
115     Returns
116     -------
117     mat_dict : dict
118        dictionary with variable names as keys, and loaded matrices as
119        values
120 
121     Notes
122     -----
123     v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.
124 
125     You will need an HDF5 python library to read matlab 7.3 format mat
126     files.  Because scipy does not supply one, we do not implement the
127     HDF5 / 7.3 interface here.
128 
129     """
130     variable_names = kwargs.pop('variable_names', None)
131     MR = mat_reader_factory(file_name, appendmat, **kwargs)
132     matfile_dict = MR.get_variables(variable_names)
133     if mdict is not None:
134         mdict.update(matfile_dict)
135     else:
136         mdict = matfile_dict
137     if isinstance(file_name, string_types):
138         MR.mat_stream.close()
139     return mdict
140 
141 
142 @docfiller
143 def savemat(file_name, mdict,
144             appendmat=True,
145             format='5',
146             long_field_names=False,
147             do_compression=False,
148             oned_as='row'):
149     """
150     Save a dictionary of names and arrays into a MATLAB-style .mat file.
151 
152     This saves the array objects in the given dictionary to a MATLAB-
153     style .mat file.
154 
155     Parameters
156     ----------
157     file_name : str or file-like object
158         Name of the .mat file (.mat extension not needed if ``appendmat ==
159         True``).
160         Can also pass open file_like object.
161     mdict : dict
162         Dictionary from which to save matfile variables.
163     appendmat : bool, optional
164         True (the default) to append the .mat extension to the end of the
165         given filename, if not already present.
166     format : {'5', '4'}, string, optional
167         '5' (the default) for MATLAB 5 and up (to 7.2),
168         '4' for MATLAB 4 .mat files
169     long_field_names : bool, optional
170         False (the default) - maximum field name length in a structure is
171         31 characters which is the documented maximum length.
172         True - maximum field name length in a structure is 63 characters
173         which works for MATLAB 7.6+
174     do_compression : bool, optional
175         Whether or not to compress matrices on write.  Default is False.
176     oned_as : {'row', 'column'}, optional
177         If 'column', write 1-D numpy arrays as column vectors.
178         If 'row', write 1-D numpy arrays as row vectors.
179 
180     See also
181     --------
182     mio4.MatFile4Writer
183     mio5.MatFile5Writer
184     """
185     file_is_string = isinstance(file_name, string_types)
186     if file_is_string:
187         if appendmat and file_name[-4:] != ".mat":
188             file_name = file_name + ".mat"
189         file_stream = open(file_name, 'wb')
190     else:
191         if not hasattr(file_name, 'write'):
192             raise IOError('Writer needs file name or writeable '
193                            'file-like object')
194         file_stream = file_name
195     if format == '4':
196         if long_field_names:
197             raise ValueError("Long field names are not available for version 4 files")
198         MW = MatFile4Writer(file_stream, oned_as)
199     elif format == '5':
200         MW = MatFile5Writer(file_stream,
201                             do_compression=do_compression,
202                             unicode_strings=True,
203                             long_field_names=long_field_names,
204                             oned_as=oned_as)
205     else:
206         raise ValueError("Format should be '4' or '5'")
207     MW.put_variables(mdict)
208     if file_is_string:
209         file_stream.close()
210 
211 
212 @docfiller
213 def whosmat(file_name, appendmat=True, **kwargs):
214     """
215     List variables inside a MATLAB file
216 
217     .. versionadded:: 0.12.0
218 
219     Parameters
220     ----------
221     %(file_arg)s
222     %(append_arg)s
223     %(load_args)s
224     %(struct_arg)s
225 
226     Returns
227     -------
228     variables : list of tuples
229         A list of tuples, where each tuple holds the matrix name (a string),
230         its shape (tuple of ints), and its data class (a string).
231         Possible data classes are: int8, uint8, int16, uint16, int32, uint32,
232         int64, uint64, single, double, cell, struct, object, char, sparse,
233         function, opaque, logical, unknown.
234 
235     Notes
236     -----
237     v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.
238 
239     You will need an HDF5 python library to read matlab 7.3 format mat
240     files.  Because scipy does not supply one, we do not implement the
241     HDF5 / 7.3 interface here.
242 
243     """
244     ML = mat_reader_factory(file_name, **kwargs)
245     variables = ML.list_variables()
246     if isinstance(file_name, string_types):
247         ML.mat_stream.close()
248     return variables
249
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scipy/io/matlab/mio.py b/scipy/io/matlab/mio.py
--- a/scipy/io/matlab/mio.py
+++ b/scipy/io/matlab/mio.py
@@ -24,8 +24,11 @@
         except IOError as e:
             if appendmat and not file_like.endswith('.mat'):
                 file_like += '.mat'
-                return open(file_like, 'rb')
-            raise IOError(e)
+                try:
+                    return open(file_like, 'rb')
+                except IOError:
+                    pass  # Rethrow the original exception.
+            raise
     # not a string - maybe file-like object
     try:
         file_like.read(0)

{"golden_diff": "diff --git a/scipy/io/matlab/mio.py b/scipy/io/matlab/mio.py\n--- a/scipy/io/matlab/mio.py\n+++ b/scipy/io/matlab/mio.py\n@@ -24,8 +24,11 @@\n         except IOError as e:\n             if appendmat and not file_like.endswith('.mat'):\n                 file_like += '.mat'\n-                return open(file_like, 'rb')\n-            raise IOError(e)\n+                try:\n+                    return open(file_like, 'rb')\n+                except IOError:\n+                    pass  # Rethrow the original exception.\n+            raise\n     # not a string - maybe file-like object\n     try:\n         file_like.read(0)\n", "issue": "Inconsistent exceptions raised by scipy.io.loadmat\nDepending on whether loadmat is passed a non-existent filename with or without the \".mat\" extension, the exception raised chages from IOError to FileNotFoundError.  I believe an easy patch would be to simply change `scipy.io.matlab.mio._open_file` to re-raise rather than raise `IOError(e)`.\n\n", "before_files": [{"content": "\"\"\"\nModule for reading and writing matlab (TM) .mat files\n\"\"\"\n# Authors: Travis Oliphant, Matthew Brett\n\nfrom __future__ import division, print_function, absolute_import\n\nimport numpy as np\n\nfrom scipy.lib.six import string_types\n\nfrom .miobase import get_matfile_version, docfiller\nfrom .mio4 import MatFile4Reader, MatFile4Writer\nfrom .mio5 import MatFile5Reader, MatFile5Writer\n\n__all__ = ['mat_reader_factory', 'loadmat', 'savemat', 'whosmat']\n\n\ndef _open_file(file_like, appendmat):\n    ''' Open `file_like` and return as file-like object '''\n    if isinstance(file_like, string_types):\n        try:\n            return open(file_like, 'rb')\n        except IOError as e:\n            if appendmat and not file_like.endswith('.mat'):\n                file_like += '.mat'\n                return open(file_like, 'rb')\n            raise IOError(e)\n    # not a string - maybe file-like object\n    try:\n        file_like.read(0)\n    except AttributeError:\n        raise IOError('Reader needs file name or open file-like object')\n    return file_like\n\n\n@docfiller\ndef mat_reader_factory(file_name, appendmat=True, **kwargs):\n    \"\"\"Create reader for matlab .mat format files\n\n    Parameters\n    ----------\n    %(file_arg)s\n    %(append_arg)s\n    %(load_args)s\n    %(struct_arg)s\n\n    Returns\n    -------\n    matreader : MatFileReader object\n       Initialized instance of MatFileReader class matching the mat file\n       type detected in `filename`.\n    \"\"\"\n    byte_stream = _open_file(file_name, appendmat)\n    mjv, mnv = get_matfile_version(byte_stream)\n    if mjv == 0:\n        return MatFile4Reader(byte_stream, **kwargs)\n    elif mjv == 1:\n        return MatFile5Reader(byte_stream, **kwargs)\n    elif mjv == 2:\n        raise NotImplementedError('Please use HDF reader for matlab v7.3 files')\n    else:\n        raise TypeError('Did not recognize version %s' % mjv)\n\n\n@docfiller\ndef loadmat(file_name, mdict=None, appendmat=True, **kwargs):\n    \"\"\"\n    Load MATLAB file\n\n    Parameters\n    ----------\n    file_name : str\n       Name of the mat file (do not need .mat extension if\n       appendmat==True) Can also pass open file-like object.\n    m_dict : dict, optional\n        Dictionary in which to insert matfile variables.\n    appendmat : bool, optional\n       True to append the .mat extension to the end of the given\n       filename, if not already present.\n    byte_order : str or None, optional\n       None by default, implying byte order guessed from mat\n       file. Otherwise can be one of ('native', '=', 'little', '<',\n       'BIG', '>').\n    mat_dtype : bool, optional\n       If True, return arrays in same dtype as would be loaded into\n       MATLAB (instead of the dtype with which they are saved).\n    squeeze_me : bool, optional\n       Whether to squeeze unit matrix dimensions or not.\n    chars_as_strings : bool, optional\n       Whether to convert char arrays to string arrays.\n    matlab_compatible : bool, optional\n       Returns matrices as would be loaded by MATLAB (implies\n       squeeze_me=False, chars_as_strings=False, mat_dtype=True,\n       struct_as_record=True).\n    struct_as_record : bool, optional\n       Whether to load MATLAB structs as numpy record arrays, or as\n       old-style numpy arrays with dtype=object.  Setting this flag to\n       False replicates the behavior of scipy version 0.7.x (returning\n       numpy object arrays).  The default setting is True, because it\n       allows easier round-trip load and save of MATLAB files.\n    verify_compressed_data_integrity : bool, optional\n        Whether the length of compressed sequences in the MATLAB file\n        should be checked, to ensure that they are not longer than we expect.\n        It is advisable to enable this (the default) because overlong\n        compressed sequences in MATLAB files generally indicate that the\n        files have experienced some sort of corruption.\n    variable_names : None or sequence\n        If None (the default) - read all variables in file. Otherwise\n        `variable_names` should be a sequence of strings, giving names of the\n        matlab variables to read from the file.  The reader will skip any\n        variable with a name not in this sequence, possibly saving some read\n        processing.\n\n    Returns\n    -------\n    mat_dict : dict\n       dictionary with variable names as keys, and loaded matrices as\n       values\n\n    Notes\n    -----\n    v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.\n\n    You will need an HDF5 python library to read matlab 7.3 format mat\n    files.  Because scipy does not supply one, we do not implement the\n    HDF5 / 7.3 interface here.\n\n    \"\"\"\n    variable_names = kwargs.pop('variable_names', None)\n    MR = mat_reader_factory(file_name, appendmat, **kwargs)\n    matfile_dict = MR.get_variables(variable_names)\n    if mdict is not None:\n        mdict.update(matfile_dict)\n    else:\n        mdict = matfile_dict\n    if isinstance(file_name, string_types):\n        MR.mat_stream.close()\n    return mdict\n\n\n@docfiller\ndef savemat(file_name, mdict,\n            appendmat=True,\n            format='5',\n            long_field_names=False,\n            do_compression=False,\n            oned_as='row'):\n    \"\"\"\n    Save a dictionary of names and arrays into a MATLAB-style .mat file.\n\n    This saves the array objects in the given dictionary to a MATLAB-\n    style .mat file.\n\n    Parameters\n    ----------\n    file_name : str or file-like object\n        Name of the .mat file (.mat extension not needed if ``appendmat ==\n        True``).\n        Can also pass open file_like object.\n    mdict : dict\n        Dictionary from which to save matfile variables.\n    appendmat : bool, optional\n        True (the default) to append the .mat extension to the end of the\n        given filename, if not already present.\n    format : {'5', '4'}, string, optional\n        '5' (the default) for MATLAB 5 and up (to 7.2),\n        '4' for MATLAB 4 .mat files\n    long_field_names : bool, optional\n        False (the default) - maximum field name length in a structure is\n        31 characters which is the documented maximum length.\n        True - maximum field name length in a structure is 63 characters\n        which works for MATLAB 7.6+\n    do_compression : bool, optional\n        Whether or not to compress matrices on write.  Default is False.\n    oned_as : {'row', 'column'}, optional\n        If 'column', write 1-D numpy arrays as column vectors.\n        If 'row', write 1-D numpy arrays as row vectors.\n\n    See also\n    --------\n    mio4.MatFile4Writer\n    mio5.MatFile5Writer\n    \"\"\"\n    file_is_string = isinstance(file_name, string_types)\n    if file_is_string:\n        if appendmat and file_name[-4:] != \".mat\":\n            file_name = file_name + \".mat\"\n        file_stream = open(file_name, 'wb')\n    else:\n        if not hasattr(file_name, 'write'):\n            raise IOError('Writer needs file name or writeable '\n                           'file-like object')\n        file_stream = file_name\n    if format == '4':\n        if long_field_names:\n            raise ValueError(\"Long field names are not available for version 4 files\")\n        MW = MatFile4Writer(file_stream, oned_as)\n    elif format == '5':\n        MW = MatFile5Writer(file_stream,\n                            do_compression=do_compression,\n                            unicode_strings=True,\n                            long_field_names=long_field_names,\n                            oned_as=oned_as)\n    else:\n        raise ValueError(\"Format should be '4' or '5'\")\n    MW.put_variables(mdict)\n    if file_is_string:\n        file_stream.close()\n\n\n@docfiller\ndef whosmat(file_name, appendmat=True, **kwargs):\n    \"\"\"\n    List variables inside a MATLAB file\n\n    .. versionadded:: 0.12.0\n\n    Parameters\n    ----------\n    %(file_arg)s\n    %(append_arg)s\n    %(load_args)s\n    %(struct_arg)s\n\n    Returns\n    -------\n    variables : list of tuples\n        A list of tuples, where each tuple holds the matrix name (a string),\n        its shape (tuple of ints), and its data class (a string).\n        Possible data classes are: int8, uint8, int16, uint16, int32, uint32,\n        int64, uint64, single, double, cell, struct, object, char, sparse,\n        function, opaque, logical, unknown.\n\n    Notes\n    -----\n    v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.\n\n    You will need an HDF5 python library to read matlab 7.3 format mat\n    files.  Because scipy does not supply one, we do not implement the\n    HDF5 / 7.3 interface here.\n\n    \"\"\"\n    ML = mat_reader_factory(file_name, **kwargs)\n    variables = ML.list_variables()\n    if isinstance(file_name, string_types):\n        ML.mat_stream.close()\n    return variables\n", "path": "scipy/io/matlab/mio.py"}], "after_files": [{"content": "\"\"\"\nModule for reading and writing matlab (TM) .mat files\n\"\"\"\n# Authors: Travis Oliphant, Matthew Brett\n\nfrom __future__ import division, print_function, absolute_import\n\nimport numpy as np\n\nfrom scipy.lib.six import string_types\n\nfrom .miobase import get_matfile_version, docfiller\nfrom .mio4 import MatFile4Reader, MatFile4Writer\nfrom .mio5 import MatFile5Reader, MatFile5Writer\n\n__all__ = ['mat_reader_factory', 'loadmat', 'savemat', 'whosmat']\n\n\ndef _open_file(file_like, appendmat):\n    ''' Open `file_like` and return as file-like object '''\n    if isinstance(file_like, string_types):\n        try:\n            return open(file_like, 'rb')\n        except IOError as e:\n            if appendmat and not file_like.endswith('.mat'):\n                file_like += '.mat'\n                try:\n                    return open(file_like, 'rb')\n                except IOError:\n                    pass  # Rethrow the original exception.\n            raise\n    # not a string - maybe file-like object\n    try:\n        file_like.read(0)\n    except AttributeError:\n        raise IOError('Reader needs file name or open file-like object')\n    return file_like\n\n\n@docfiller\ndef mat_reader_factory(file_name, appendmat=True, **kwargs):\n    \"\"\"Create reader for matlab .mat format files\n\n    Parameters\n    ----------\n    %(file_arg)s\n    %(append_arg)s\n    %(load_args)s\n    %(struct_arg)s\n\n    Returns\n    -------\n    matreader : MatFileReader object\n       Initialized instance of MatFileReader class matching the mat file\n       type detected in `filename`.\n    \"\"\"\n    byte_stream = _open_file(file_name, appendmat)\n    mjv, mnv = get_matfile_version(byte_stream)\n    if mjv == 0:\n        return MatFile4Reader(byte_stream, **kwargs)\n    elif mjv == 1:\n        return MatFile5Reader(byte_stream, **kwargs)\n    elif mjv == 2:\n        raise NotImplementedError('Please use HDF reader for matlab v7.3 files')\n    else:\n        raise TypeError('Did not recognize version %s' % mjv)\n\n\n@docfiller\ndef loadmat(file_name, mdict=None, appendmat=True, **kwargs):\n    \"\"\"\n    Load MATLAB file\n\n    Parameters\n    ----------\n    file_name : str\n       Name of the mat file (do not need .mat extension if\n       appendmat==True) Can also pass open file-like object.\n    m_dict : dict, optional\n        Dictionary in which to insert matfile variables.\n    appendmat : bool, optional\n       True to append the .mat extension to the end of the given\n       filename, if not already present.\n    byte_order : str or None, optional\n       None by default, implying byte order guessed from mat\n       file. Otherwise can be one of ('native', '=', 'little', '<',\n       'BIG', '>').\n    mat_dtype : bool, optional\n       If True, return arrays in same dtype as would be loaded into\n       MATLAB (instead of the dtype with which they are saved).\n    squeeze_me : bool, optional\n       Whether to squeeze unit matrix dimensions or not.\n    chars_as_strings : bool, optional\n       Whether to convert char arrays to string arrays.\n    matlab_compatible : bool, optional\n       Returns matrices as would be loaded by MATLAB (implies\n       squeeze_me=False, chars_as_strings=False, mat_dtype=True,\n       struct_as_record=True).\n    struct_as_record : bool, optional\n       Whether to load MATLAB structs as numpy record arrays, or as\n       old-style numpy arrays with dtype=object.  Setting this flag to\n       False replicates the behavior of scipy version 0.7.x (returning\n       numpy object arrays).  The default setting is True, because it\n       allows easier round-trip load and save of MATLAB files.\n    verify_compressed_data_integrity : bool, optional\n        Whether the length of compressed sequences in the MATLAB file\n        should be checked, to ensure that they are not longer than we expect.\n        It is advisable to enable this (the default) because overlong\n        compressed sequences in MATLAB files generally indicate that the\n        files have experienced some sort of corruption.\n    variable_names : None or sequence\n        If None (the default) - read all variables in file. Otherwise\n        `variable_names` should be a sequence of strings, giving names of the\n        matlab variables to read from the file.  The reader will skip any\n        variable with a name not in this sequence, possibly saving some read\n        processing.\n\n    Returns\n    -------\n    mat_dict : dict\n       dictionary with variable names as keys, and loaded matrices as\n       values\n\n    Notes\n    -----\n    v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.\n\n    You will need an HDF5 python library to read matlab 7.3 format mat\n    files.  Because scipy does not supply one, we do not implement the\n    HDF5 / 7.3 interface here.\n\n    \"\"\"\n    variable_names = kwargs.pop('variable_names', None)\n    MR = mat_reader_factory(file_name, appendmat, **kwargs)\n    matfile_dict = MR.get_variables(variable_names)\n    if mdict is not None:\n        mdict.update(matfile_dict)\n    else:\n        mdict = matfile_dict\n    if isinstance(file_name, string_types):\n        MR.mat_stream.close()\n    return mdict\n\n\n@docfiller\ndef savemat(file_name, mdict,\n            appendmat=True,\n            format='5',\n            long_field_names=False,\n            do_compression=False,\n            oned_as='row'):\n    \"\"\"\n    Save a dictionary of names and arrays into a MATLAB-style .mat file.\n\n    This saves the array objects in the given dictionary to a MATLAB-\n    style .mat file.\n\n    Parameters\n    ----------\n    file_name : str or file-like object\n        Name of the .mat file (.mat extension not needed if ``appendmat ==\n        True``).\n        Can also pass open file_like object.\n    mdict : dict\n        Dictionary from which to save matfile variables.\n    appendmat : bool, optional\n        True (the default) to append the .mat extension to the end of the\n        given filename, if not already present.\n    format : {'5', '4'}, string, optional\n        '5' (the default) for MATLAB 5 and up (to 7.2),\n        '4' for MATLAB 4 .mat files\n    long_field_names : bool, optional\n        False (the default) - maximum field name length in a structure is\n        31 characters which is the documented maximum length.\n        True - maximum field name length in a structure is 63 characters\n        which works for MATLAB 7.6+\n    do_compression : bool, optional\n        Whether or not to compress matrices on write.  Default is False.\n    oned_as : {'row', 'column'}, optional\n        If 'column', write 1-D numpy arrays as column vectors.\n        If 'row', write 1-D numpy arrays as row vectors.\n\n    See also\n    --------\n    mio4.MatFile4Writer\n    mio5.MatFile5Writer\n    \"\"\"\n    file_is_string = isinstance(file_name, string_types)\n    if file_is_string:\n        if appendmat and file_name[-4:] != \".mat\":\n            file_name = file_name + \".mat\"\n        file_stream = open(file_name, 'wb')\n    else:\n        if not hasattr(file_name, 'write'):\n            raise IOError('Writer needs file name or writeable '\n                           'file-like object')\n        file_stream = file_name\n    if format == '4':\n        if long_field_names:\n            raise ValueError(\"Long field names are not available for version 4 files\")\n        MW = MatFile4Writer(file_stream, oned_as)\n    elif format == '5':\n        MW = MatFile5Writer(file_stream,\n                            do_compression=do_compression,\n                            unicode_strings=True,\n                            long_field_names=long_field_names,\n                            oned_as=oned_as)\n    else:\n        raise ValueError(\"Format should be '4' or '5'\")\n    MW.put_variables(mdict)\n    if file_is_string:\n        file_stream.close()\n\n\n@docfiller\ndef whosmat(file_name, appendmat=True, **kwargs):\n    \"\"\"\n    List variables inside a MATLAB file\n\n    .. versionadded:: 0.12.0\n\n    Parameters\n    ----------\n    %(file_arg)s\n    %(append_arg)s\n    %(load_args)s\n    %(struct_arg)s\n\n    Returns\n    -------\n    variables : list of tuples\n        A list of tuples, where each tuple holds the matrix name (a string),\n        its shape (tuple of ints), and its data class (a string).\n        Possible data classes are: int8, uint8, int16, uint16, int32, uint32,\n        int64, uint64, single, double, cell, struct, object, char, sparse,\n        function, opaque, logical, unknown.\n\n    Notes\n    -----\n    v4 (Level 1.0), v6 and v7 to 7.2 matfiles are supported.\n\n    You will need an HDF5 python library to read matlab 7.3 format mat\n    files.  Because scipy does not supply one, we do not implement the\n    HDF5 / 7.3 interface here.\n\n    \"\"\"\n    ML = mat_reader_factory(file_name, **kwargs)\n    variables = ML.list_variables()\n    if isinstance(file_name, string_types):\n        ML.mat_stream.close()\n    return variables\n", "path": "scipy/io/matlab/mio.py"}]}