title: How do I escape forward slashes in python, so that open() sees my file as a filename to write, instead of a filepath to read?
body: <p>Let me preface this by saying I'm <strong>not exactly sure</strong> what is happening with my code; I'm fairly new to programming. </p>
  
  <p>I've been working on creating an individual final project for my python CS class that checks my teacher's website on a daily basis and determines if he's changed any of the web pages on his website since the last time the program ran or not.</p>
  
  <p>The step I'm working on right now is as follows:</p>
  
  <pre><code>def write_pages_files():
      '''
      Writes the various page files from the website's links 
      '''
      links = get_site_links()
      for page in links:
          site_page = requests.get(root_url + page)
          soup = BeautifulSoup(site_page.text)
          with open(page + ".txt", mode='wt', encoding='utf-8') as out_file:
              out_file.write(str(soup))
  </code></pre>
  
  <p>The links look similar to this:</p>
  
  <blockquote>
    <p>/site/sitename/class/final-code</p>
  </blockquote>
  
  <p>And the error I get is as follows:</p>
  
  <pre><code>with open(page + ".txt", mode='wt', encoding='utf-8') as out_file:
  FileNotFoundError: [Errno 2] No such file or directory: '/site/sitename/class.txt'
  </code></pre>
  
  <p>How can I write the site pages with these types of names (/site/sitename/nameofpage.txt)?</p>