parameters: (fname, flag='r', return_opened=False)
return_statement: return fhd
docstring: Returns the filehandle corresponding to a string or a file.
      If the string ends in '.gz', the file is automatically unzipped.
      
      Parameters
      ----------
      fname : string, filehandle
          Name of the file whose filehandle must be returned.
      flag : string, optional
          Flag indicating the status of the file ('r' for read, 'w' for write).
      return_opened : boolean, optional
          Whether to return the opening status of the file.
docstring_summary: Returns the filehandle corresponding to a string or a file.
      If the string ends in '.gz', the file is automatically unzipped.
      
      Parameters
      ----------
      fname : string, filehandle
          Name of the file whose filehandle must be returned.
      flag : string, optional
          Flag indicating the status of the file ('r' for read, 'w' for write).
      return_opened : boolean, optional
          Whether to return the opening status of the file.
docstring_tokens: Returns the filehandle corresponding to a string or a file . If the string ends in . gz the file is automatically unzipped . Parameters ---------- fname : string filehandle Name of the file whose filehandle must be returned . flag : string optional Flag indicating the status of the file ( r for read w for write ) . return_opened : boolean optional Whether to return the opening status of the file .
function: def _to_filehandle(fname, flag='r', return_opened=False):
      """
      Returns the filehandle corresponding to a string or a file.
      If the string ends in '.gz', the file is automatically unzipped.
      
      Parameters
      ----------
      fname : string, filehandle
          Name of the file whose filehandle must be returned.
      flag : string, optional
          Flag indicating the status of the file ('r' for read, 'w' for write).
      return_opened : boolean, optional
          Whether to return the opening status of the file.
      """
      if _is_string_like(fname):
          if fname.endswith('.gz'):
              import gzip
              fhd = gzip.open(fname, flag)
          elif fname.endswith('.bz2'):
              import bz2
              fhd = bz2.BZ2File(fname)
          else:
              fhd = file(fname, flag)
          opened = True
      elif hasattr(fname, 'seek'):
          fhd = fname
          opened = False
      else:
          raise ValueError('fname must be a string or file handle')
      if return_opened:
          return fhd, opened
      return fhd
function_tokens: def _to_filehandle ( fname , flag = 'r' , return_opened = False ) : if _is_string_like ( fname ) : if fname . endswith ( '.gz' ) : import gzip fhd = gzip . open ( fname , flag ) elif fname . endswith ( '.bz2' ) : import bz2 fhd = bz2 . BZ2File ( fname ) else : fhd = file ( fname , flag ) opened = True elif hasattr ( fname , 'seek' ) : fhd = fname opened = False else : raise ValueError ( 'fname must be a string or file handle' ) if return_opened : return fhd , opened return fhd