title: How to handle OS errors in python
body: <p>I am trying to create linux groups using python.Below is function for creating groups.</p>
  
  <pre><code>def createGroups(self):
          adminGroupCommand="groupadd "+ self.projectName+'admin'
          userGroupCommand="groupadd "+ self.projectName+'user'
          try:
              os.system(adminGroupCommand)
          except OSError as err:
              print("group already exists: "+adminGroupCommand)
          try:
              os.system(userGroupCommand)
          except OSError as err:
              print("group already exists: "+userGroupCommand)
  </code></pre>
  
  <p>The function is successfully creating groups.But if i run the same again it gives below output when run,</p>
  
  <pre><code>groupadd: group 'akphaadmin' already exists
  groupadd: group 'akphauser' already exists
  </code></pre>
  
  <p>Its not printing my custom message  in "except"block.How can i force the function to print custom message when creating groups if they already exists.</p>