title: How do I control what parts of a python script run as root
body: <p>I'm writing a scraper for the dark web. One step involves creating a torrc file in /etc/tor/, which requires root access. To do this, I just run the python file  with sudo (i.e. 'sudo python filename.py').</p>
  
  <p>However, I encountered an error with selenium:
  <code>Running Firefox as root in a regular user's session is not supported</code></p>
  
  <p>I googled the error and found solutions on how to bypass that. I would rather not run it as root if possible. </p>
  
  <p>How can I run the first part of the code as root, but not the second part?</p>