scipy/io/mmio.py
def _open(filespec, mode='rb'):
        """ Return an open file stream for reading based on source.

        If source is a file name, open it (after trying to find it with mtx and
        gzipped mtx extensions).  Otherwise, just return source.

        Parameters
        ----------
        filespec : str or file-like
            String giving file name or file-like object
        mode : str, optional
            Mode with which to open file, if `filespec` is a file name.

        Returns
        -------
        fobj : file-like
            Open file-like object.
        close_it : bool
            True if the calling function should close this file when done,
            false otherwise.
        """
        close_it = False
        if isinstance(filespec, string_types):
            close_it = True

            # open for reading
            if mode[0] == 'r':

                # determine filename plus extension
                if not os.path.isfile(filespec):
                    if os.path.isfile(filespec+'.mtx'):
                        filespec = filespec + '.mtx'
                    elif os.path.isfile(filespec+'.mtx.gz'):
                        filespec = filespec + '.mtx.gz'
                    elif os.path.isfile(filespec+'.mtx.bz2'):
                        filespec = filespec + '.mtx.bz2'
                # open filename
                if filespec.endswith('.gz'):
                    import gzip
                    stream = gzip.open(filespec, mode)
                elif filespec.endswith('.bz2'):
                    import bz2
                    stream = bz2.BZ2File(filespec, 'rb')
                else:
                    stream = open(filespec, mode)

            # open for writing
            else:
                if filespec[-4:] != '.mtx':
                    filespec = filespec + '.mtx'
                stream = open(filespec, mode)
        else:
            stream = filespec

        return stream, close_it
 Return an open file stream for reading based on source.

        If source is a file name, open it (after trying to find it with mtx and
        gzipped mtx extensions).  Otherwise, just return source.

        Parameters
        ----------
        filespec : str or file-like
            String giving file name or file-like object
        mode : str, optional
            Mode with which to open file, if `filespec` is a file name.

        Returns
        -------
        fobj : file-like
            Open file-like object.
        close_it : bool
            True if the calling function should close this file when done,
            false otherwise.
        
Return an open file stream for reading based on source.
If source is a file name, open it (after trying to find it with mtx and
gzipped mtx extensions).  Otherwise, just return source.

Parameters

filespec : str or file-like
String giving file name or file-like object
mode : str, optional
Mode with which to open file, if `filespec` is a file name.

Returns

fobj : file-like
Open file-like object.
close_it : bool
True if the calling function should close this file when done,
false otherwise.
Return an open file stream for reading based on source . If source is a file name open it ( after trying to find it with mtx and gzipped mtx extensions ) . Otherwise just return source . Parameters filespec : str or file - like String giving file name or file - like object mode : str optional Mode with which to open file if ` filespec ` is a file name . Returns fobj : file - like Open file - like object . close_it : bool True if the calling function should close this file when done false otherwise .
def _open(filespec, mode='rb'):
        close_it = False
        if isinstance(filespec, string_types):
            close_it = True
            if mode[0] == 'r':
                if not os.path.isfile(filespec):
                    if os.path.isfile(filespec+'.mtx'):
                        filespec = filespec + '.mtx'
                    elif os.path.isfile(filespec+'.mtx.gz'):
                        filespec = filespec + '.mtx.gz'
                    elif os.path.isfile(filespec+'.mtx.bz2'):
                        filespec = filespec + '.mtx.bz2'
                if filespec.endswith('.gz'):
                    import gzip
                    stream = gzip.open(filespec, mode)
                elif filespec.endswith('.bz2'):
                    import bz2
                    stream = bz2.BZ2File(filespec, 'rb')
                else:
                    stream = open(filespec, mode)
            else:
                if filespec[-4:] != '.mtx':
                    filespec = filespec + '.mtx'
                stream = open(filespec, mode)
        else:
            stream = filespec
        return stream, close_it
def _open ( filespec , mode = 'rb' ) : close_it = False if isinstance ( filespec , string_types ) : close_it = True if mode [ 0 ] == 'r' : if not os . path . isfile ( filespec ) : if os . path . isfile ( filespec + '.mtx' ) : filespec = filespec + '.mtx' elif os . path . isfile ( filespec + '.mtx.gz' ) : filespec = filespec + '.mtx.gz' elif os . path . isfile ( filespec + '.mtx.bz2' ) : filespec = filespec + '.mtx.bz2' if filespec . endswith ( '.gz' ) : import gzip stream = gzip . open ( filespec , mode ) elif filespec . endswith ( '.bz2' ) : import bz2 stream = bz2 . BZ2File ( filespec , 'rb' ) else : stream = open ( filespec , mode ) else : if filespec [ - 4 : ] != '.mtx' : filespec = filespec + '.mtx' stream = open ( filespec , mode ) else : stream = filespec return stream , close_it
Return an open file stream for reading based on source.
Return an open file stream for reading based on source .
""" Return an open file stream for reading based on source.

        If source is a file name, open it (after trying to find it with mtx and
        gzipped mtx extensions).  Otherwise, just return source.

        Parameters
        ----------
        filespec : str or file-like
            String giving file name or file-like object
        mode : str, optional
            Mode with which to open file, if `filespec` is a file name.

        Returns
        -------
        fobj : file-like
            Open file-like object.
        close_it : bool
            True if the calling function should close this file when done,
            false otherwise.
        """ # open for reading # determine filename plus extension # open filename # open for writing
filespec
mode