title: Update python itself using the apt module
body: <p>I am writing a python script that will run on an EC2 machine as the <a href="http://alestic.com/2009/06/ec2-user-data-scripts" rel="nofollow">user-data-script</a>. I'm trying to figure out how I can upgrade the packages on the machine similar to the bash command:</p>
  
  <pre><code>$ sudo apt-get -qqy update &amp;&amp; sudo apt-get -qqy upgrade
  </code></pre>
  
  <p>I know I can use the <code>apt</code> package in python to do this:</p>
  
  <pre><code>import apt
  cache=apt.Cache()
  cache.update()
  cache.open(None)
  cache.upgrade()
  cache.commit()
  </code></pre>
  
  <p>Problem is what happens if python itself was one of the packages that was upgraded. Is there a way to reload the interpreter and script following this upgrade and continue where it left off?</p>
  
  <p>Right now my only choice is to use a shell script as my user-data script for the sole purpose of upgrading packages (including possibly python) and then dropping into python for the rest of my code. I'd like to eliminate the extra step of using a shell script.</p>