title: How to receive uncertain numbers of return values in python
body: <p><strong>Update:</strong> I am writing a decorator of flask app. The aim of it is to wrap the response in the struct like this:</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;code&quot;: 0,
      &quot;message&quot;: &quot;successful&quot;,
      &quot;data&quot;: null
  }
  </code></pre>
  <p>And for the view function, it only needs to return the content of <code>data</code>. If some exceptions occur, the view function would to return a second value <code>code</code>.</p>
  <p>The code snippet of the decorator:</p>
  <pre class="lang-py prettyprint-override"><code>def foo():
      resp = {
          &quot;code&quot;: 0,
          &quot;message&quot;: &quot;successful&quot;,
          &quot;data&quot;: None,
      }
  
      data, code = func(*args, **kwargs)
      if code == 0 or not code:
          resp['data'] = data
      else:
          resp = build_exception_resp(code, data)
  </code></pre>
  <p>The problem is, if everything is ok, I only want to return the <code>data</code>; and only if there are something wrong, the second value <code>code</code> should be returned.</p>
  <p>Original description:</p>
  <p>For example:</p>
  <pre class="lang-py prettyprint-override"><code>
  def foo():
      i = int(input())
      if i == 0:
          return 0, 0
      else:
          return 0
  
  a, b = foo()
  </code></pre>
  <p>The length of return value is uncertain, and in the second case, it would throw an cannot unpack error. Are there any pythonic way to do this?</p>