[CentralOH] Indicating Meaning of Items of Return Values

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Mon Mar 12 14:54:45 CET 2012


On Sun, 11 Mar 2012 18:44:10 -0400, Mark E Erbaugh <mark at microenh.com> wrote:

> On Mar 11, 2012, at 6:37 PM, jep200404 at columbus.rr.com wrote:

> > How do you indicate _meaning_? 

> How about:
> 
> search,holy,grail = foo()

Thanks. That answers the question I asked. Unfortunately, 
I oversimplified my example. Those tuples get stored in 
containers of containers. When accessing those tuples 
later, names no longer apply. 

On Sun, 11 Mar 2012 18:55:17 -0400, Brandon Craig Rhodes <brandon at rhodesmill.org> wrote:

> jep200404 at columbus.rr.com writes:
> 
> > 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?
> 
> The usual way would be to return an object.
> 
>     class GrailSearchResult(object):
>         """..."""
> 
>     def foo():
>         r = GrailSearchResult()
>         r.search = ...
>         r.holy = ...
>         r.grail = ...
>         return r
> 
> But if the "usual Python way" of representing a compound value seems too
> heavyweight, the "collections.namedtuple" type supports objects that all
> have the exact same set of attributes. 

Thanks. Those are more like I was thinking about (but failed to 
ask a better question for). The namedtuple looks interesting, 
much like structs in C. Python's libraries continue to impress. 



More information about the CentralOH mailing list