title: How do I make a Python function with mutually exclusive arguments?
body: <p>I have a Python class which needs to accept one of two mutually exclusive arguments. If the arguments are not exclusive, (ie: if both or neither are given), an error should be raised.</p>
  
  <pre><code>class OrgLocation:
      __init__(self, location_num=None, location_path=None):
          """location_num &amp; location_path are mutually exclusive"""
  </code></pre>
  
  <p>In most scenarios, the best option would be to make two separate classes. However, I am working with <a href="https://stackoverflow.com/q/9812136/3357935">an external API</a> which <em>requires</em> these two attributes to be mutually exclusive.</p>
  
  <p>Request:</p>
  
  <pre><code>&lt;OrgLocation LocationPathName="ROOT/BU/DIV/SL/DEPT/JOB" LocationNum="1234"/&gt;
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>&lt;Error Message="Use either LocationNum or LocationPathName but not both." ErrorCode="1186"&gt;
  </code></pre>
  
  <hr>
  
  <p>Similar questions seem to indicate that <a href="https://docs.python.org/3/library/argparse.html" rel="noreferrer"><code>argparse</code></a> can be used for mutually exclusive arguments in command-line interfaces, but I'm unsure how to apply this to a class constructor</p>
  
  <p>How can I create a Python function with mutually exclusive arguments?</p>