This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: add possibility for returning value the way Matlab does it
Type: enhancement Stage: resolved
Components: Interpreter Core Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Geza, brian.curtin
Priority: normal Keywords:

Created on 2011-02-11 18:31 by Geza, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg128416 - (view) Author: Geza (Geza) Date: 2011-02-11 18:31
It would be nice if you could write a function like this (besides, of course, the current way):

def result=functionname(params):
  ...
  result=something

It would suffice for most functions, since you usually always return one type of value, and it can be very convenient in certain cases.
This is the way it is done e.g. in Matlab.

Advantages: 
- You can easily see what the function returns (e.g. by writing a tuple as the return value), without having to read the function body, or without hoping to find it in the comments.
- You can initialize the return values, and then care about the cases where they change.
- If you change the setup of the return value (e.g. insert a new item into the tuple), you do not need to change the "return" statement at possibly several places in the function body.

Disadvantages:
- I suggest it as an addition, so there isn't really. One person may decide to use one way, one the other.
- Of course, if you mix using the two ways, you may need to look at the function header to see which one you used.

Some more details to the idea:
- The return values are initialized to None.
- You can use the "return" statement just as before, but without arguments, to return from anywhere in the code.
- If you specify arguments to the "return" statement, Python stops with an exception.

The idea at this stage of Python development may be surprising, but I hope that nevertheless you will consider the idea seriously.

Thanks, and best regard!
msg128417 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2011-02-11 18:33
A change like this would need to go through, at the least, the python-ideas mailing list. Please submit your idea there first.
History
Date User Action Args
2022-04-11 14:57:12adminsetgithub: 55405
2011-02-11 18:33:43brian.curtinsetstatus: open -> closed

nosy: + brian.curtin
messages: + msg128417

resolution: rejected
stage: resolved
2011-02-11 18:31:22Gezacreate