title: How to troubleshoot "NotADirectoryError: [Errno 20] Not a directory:"?
body: <p>I don't understand why I'm receiving this an error. </p>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>File "/home/user/my_script.py", line 37, in my_script
      os.replace(temp_file.name, file_name)
  NotADirectoryError: [Errno 20] Not a directory: '/home/user/folder/tmpep07qkgk' -&gt; '/home/user/folder/'
  </code></pre>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>file_name = config['filename']
  file_format = config['format']
  
  if file_format == 'yml':
      with tempfile.NamedTemporaryFile(mode='w', dir=os.path.dirname(file_name), delete=False) as temp_file:
          yaml.safe_dump(convert_to_dict(data), temp_file)
      os.replace(temp_file.name, file_name) # LINE 37
      logger.info('Saved to file: {}'.format(file_name))
  </code></pre>