New submission from Geza <kge...@gmail.com>:

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!

----------
components: Interpreter Core
messages: 128416
nosy: Geza
priority: normal
severity: normal
status: open
title: add possibility for returning value the way Matlab does it
type: feature request

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11196>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to