title: How to execute os.* methods as root?
body: <p>Is it possible to ask for a root pw without storing in in my script memory and to run some of os.* commands as root?</p>
  
  <p>My script</p>
  
  <ol>
  <li>scans some folders and files to check if it can do the job</li>
  <li>makes some changes in /etc/...</li>
  <li>creates a folder and files that should be owned by the user who ran the script</li>
  </ol>
  
  <p>(1) can be done as a normal user. I can do (2) by sudoing the script, but then the folder and files in (3) will be root's.</p>
  
  <p>The issue is that I use a lot of os.makedirs, os.symlink, etc, which stops me from making it runnable by a normal user.</p>
  
  <p><strong>Tanks 2 all for suggestions</strong></p>
  
  <p>The solution so far is:</p>
  
  <pre><code># do all in sudo
  os.chown(folder, int(os.getenv('SUDO_UID')), int(os.getenv('SUDO_GID')))
  </code></pre>
  
  <p>thanks to <em>gnibbler</em> for hint.</p>