title: Python: How to get group ids of one username (like id -Gn )
body: <p><code>getpwname</code> can only get the <code>gid</code> of a <code>username</code>.</p>
  
  <pre><code>import pwd
  myGroupId = pwd.getpwnam(username).pw_gid
  </code></pre>
  
  <p><code>getgroups</code> can only get <code>groups</code> of the script user.</p>
  
  <pre><code>import os
  myGroupIds = os.getgroups()
  </code></pre>
  
  <p>How can I get all <code>groups</code> of one arbitrary <code>username</code>, like the <code>id -Gn</code> command?</p>
  
  <pre><code>id -Gn `whoami`
  </code></pre>