Looking for the best way to translate an idiom
James Stroud
jstroud at mbi.ucla.edu
Sun Dec 14 18:42:18 EST 2008
Paul Moore wrote:
> I'm translating some code from another language (Lua) which has
> multiple function return values. So, In Lua, it's possible to define a
> function
>
> function f()
> return 1,2,3
> end
>
> which returns 3 values. These can then be used/assigned by the caller:
>
> a,b,c = f()
>
> So far, much like Python, but the key difference is that in Lua,
> excess arguments are ignored - so you can do
py> class mytuple(tuple):
def magic(self, astr):
names = astr.split()
for name, val in zip(names, self):
globals()[name] = val
...
py> t = mytuple((1,2,3))
py> t.magic('a b')
py> a
1
py> b
2
James
More information about the Python-list
mailing list