title: How to change owner of a file in python
body: <p>I am trying to change owner of a file. I am currently logged as user1 and trying to set ownership to user2. I need to run chown as sudo(root) because the parent directory's permissions does not allow user1 to change ownership.</p>
  
  <p>When I run the following code I get an error:</p>
  
  <pre><code>&gt;&gt;&gt; getpass.getuser() #current user
  'user1'
  
  &gt;&gt;&gt; os.chown("/me.txt", uid, gid)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  OSError: [Errno 1] Operation not permitted: '/me.txt'
  </code></pre>
  
  <p>where uid and gid are for user2.</p>