Skip to main content

multi-value-return pattern in Python

Project description

originally, you have:

def func():
    return 1
print func() + func()

Then you decided that func() can return some extra information but you don’t want to break previous code (or modify them one by one). It looks like

def func():
    return 1, "extra info"
value, extra = func()
print value # 1 (expected)
print extra # extra info (expected)
print func() + func() # (1, 'extra info', 1, 'extra info') (not expected, we want the previous behaviour, i.e. 2)

The previous codes (func() + func()) are broken. You have to fix it.

The solution is adapted from the answer,

http://stackoverflow.com/questions/17648591/multiple-value-return-pattern-in-python-not-tuple-list-dict-or-object-soluti/17680730#17680730

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
multiret-0.0.1.tar.gz (1.5 kB) Copy SHA256 hash SHA256 Source None Jul 21, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page