Looking for the best way to translate an idiom

Paul Moore p.f.moore at gmail.com
Sun Dec 14 18:51:03 CET 2008


On 14 Dec, 16:22, Bruno Desthuilliers
<bdesth.quelquech... at free.quelquepart.fr> wrote:
> if you only want the first returned value, you can just apply a slice:
>
> def f():
>     return 1,2,3
>
> a = f()[0] + 1

Hmm, true. I'm not sure it's any less ugly, though :-)

> FWIW, Python 2.6 has NamedTuple objects...

I know, but I want to target 2.5+ (I still have a number of systems
running 2.5)

> > - have 2 calls, one to return just the position, one to return both.
> > This feels awkward, because of the 2 method names to remember.
>
> You forgot one solution: passing a flag to the function to specify if
> you want only the main result or the extra ones as well, and give this
> flag the appropriate default value depending on most common use case.

True, that's another option. It might work, I'll think about it.

> The one that happens to be the most simple for the most common usecase,
> while still providing support for more advanced stuff.

Exactly. I'll have to think some more about real use cases.

> > I suspect my intuition isn't accurate here, as most of the use I've
> > made of the library is in writing tests, which isn't typical use :-(
>
> So perhaps you should start writing some real-life code ?

:-) Once I have a library that's functional enough to do so, I may
well. Chicken and egg situation, to some extent... And I don't really
feel like switching to Lua just to get a feel for how the library gets
used!

> > Thanks for any assistance.
>
> Not sure I've been that helpful. Sorry...

Any feedback helps. Thanks for taking the time.

Paul.



More information about the Python-list mailing list