title: Using sudo with Python script
body: <p>I'm trying to write a small script to mount a VirtualBox shared folder each time I execute the script. I want to do it with Python, because I'm trying to learn it for scripting.</p>
  
  <p>The problem is that I need privileges to launch mount command. I could run the script as sudo, but I prefer it to make sudo by its own.</p>
  
  <p>I already know that it is not safe to write your password into a .py file, but we are talking about a virtual machine that is not critical at all: I just want to click the .py script and get it working.</p>
  
  <p>This is my attempt:</p>
  
  <pre><code>#!/usr/bin/env python
  import subprocess
  
  sudoPassword = 'mypass'
  command = 'mount -t vboxsf myfolder /home/myuser/myfolder'
  
  subprocess.Popen('sudo -S' , shell=True,stdout=subprocess.PIPE)
  subprocess.Popen(sudoPassword , shell=True,stdout=subprocess.PIPE)
  subprocess.Popen(command , shell=True,stdout=subprocess.PIPE)
  </code></pre>
  
  <p>My python version is 2.6</p>