code: def open_file(filename, file_mode='w'):
          
          if six.PY2:
              # Open with codecs to define text mode
              return codecs.open(filename, mode=file_mode, encoding='utf-8')
  
          return open(filename, file_mode, encoding='utf8')
docs: A static convenience function that performs the open of the recorder
          file correctly for different versions of Python.
  
          *New in pywbem 0.10.*
  
          This covers the issue where the file should be opened in text mode but
          that is done differently in Python 2 and Python 3.
  
          The returned file-like object must be closed by the caller.
  
          Parameters:
  
            filename(:term:`string`):
              Name of the file where the recorder output will be written
  
            file_mode(:term:`string`):
              Optional file mode.  The default is 'w' which overwrites any
              existing file.  if 'a' is used, the data is appended to any
              existing file.
  
          Returns:
  
            File-like object.
  
          Example::
  
              recorder = TestClientRecorder(...)
              recorder_file = recorder.open_file('recorder.log')
  
              . . . # Perform WBEM operations using the recorder
  
              recorder_file.close()