[CentralOH] Indicating Meaning of Items of Return Values
Steven Huwig
steven.huwig at gmail.com
Sun Mar 11 23:48:52 CET 2012
Describe the return values separately in a docstring for the method or function.
def foo():
"""Returns (search, holy, grail), where search is..."""
...
return search, holy, grail
On Mar 11, 2012, at 6:37 PM, jep200404 at columbus.rr.com wrote:
> How do you indicate _meaning_?
>
> When returning multiple things such as in a tuple or list
> from a function or method, what are good ways of referring to the
> individual items that convey _meaning?
>
> For example, the indexes of bar leave no clue as to what
> its items mean in the following code.
>
> def foo():
> ...
> return search, holy, grail
>
> def main():
> bar = foo()
>
> # The indexes of bar give no clue as to meaning.
> snafu = bar[0] * bar[1] + bar[2]
>
> I am playing with the following to indicate meaning.
>
> # Indexes for return values are:
> (SEARCH, HOLY, GRAIL) = range(3)
> def foo():
> ...
> return search, holy, grail
>
> def main():
> bar = foo()
>
> snafu = bar[SEARCH] * bar[HOLY] + bar[GRAIL]
>
> What are better ways of conveying meaning?
> The normal way of returning things is with a tuple,
> of which the items are accessed by numerical index.
> Should I return a dictionary as follows?
> That seems too much.
>
> def foo():
> ...
> return {"SEARCH": search, "HOLY": holy, "GRAIL": grail}
>
> def main():
> bar = foo()
>
> snafu = bar{"SEARCH"} * bar{"HOLY"} + bar{"GRAIL"}
>
> How do you indicate _meaning_?
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
More information about the CentralOH
mailing list