title: os.path AttributeError: 'str' object has no attribute 'exists'
body: <p>I'm trying to reproduce the code from this site: <a href="https://www.guru99.com/python-copy-file.html" rel="noreferrer">https://www.guru99.com/python-copy-file.html</a></p>
  
  <p>The general idea is to copy a file using python. Although I can work my way around the errors, I also <strong>want to understand what I'm doing wrong</strong> in this case.</p>
  
  <pre><code>import shutil
  from os import path
  def main(filename):
      if path.exists(filename):
          src = path.realpath(filename)
          head, tail = path.split(src)
          dst = src + ".bak"
          shutil.copy(src,dst)
  
  main('C:\\Users\\test.txt') #This raises the error
  main('test.txt') #This works, if the file is in the same folder as the py script
  </code></pre>
  
  <p>If used with the full directory (main('C:\Users\test.txt')) The code returns the error <code>AttributeError: 'str' object has no attribute 'exists'</code>. If I remove the line with <code>path.exists()</code> I get a similar error: <code>AttributeError: 'str' object has no attribute 'realpath'</code>.
  By using the filename <code>main('test.txt')</code> everything works, as long as the file is in the same folder as the python script that contains the function.</p>
  
  <p>So I tried reading the <a href="https://docs.python.org/3/library/os.path.html" rel="noreferrer">docs</a>, which states for both <code>path.exists()</code> and <code>path.realpath()</code>:</p>
  
  <blockquote>
    <p>Changed in version 3.6: Accepts a path-like object.</p>
  </blockquote>
  
  <p>Since <strong>I'm running 3.7.1</strong> I went foward to check what is a "path-like object":</p>
  
  <blockquote>
    <p>An object representing a file system path. A path-like object is either a str or bytes object representing a path, or an object implementing the os.PathLike protocol. An object that supports the os.PathLike protocol can be converted to a str or bytes file system path by calling the os.fspath() function; os.fsdecode() and os.fsencode() can be used to guarantee a str or bytes result instead, respectively. Introduced by PEP 519.</p>
  </blockquote>
  
  <p>From that, given that I provided a string, I take it should be working. So what I'm missing?</p>