Very simple request about argument setting.

ArdPy ardsrk at gmail.com
Mon Oct 30 07:21:15 CET 2006


Hakusa at gmail.com wrote:
> ArdPy wrote:
> > There is an error in the syntax the star must prefix the variable name
> > not suffix it.
> > Then the items variable will accept the parameter value as a tuple.
>
> Hmm, tuples are immutable, right? I need something mutable so that when
> the player picks up an item, it's no longer in the room.
>
> Besides which, I've been playing with this whole thing in the
> interactive interpreter:
>
> >>> def shuf(x,*foo, **bar):
> ... 	return x, foo
> ...
> >>> x,foo,bar = shuf(1,2,3,4,5,6,7,8)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
> ValueError: need more than 2 values to unpack
>
> I remember that two stars is for the second tuple, but how do I
> distinguish between what var is for which tuple? I've tried using
> brackets, braces, prenthisies, nothing seems to work. So what I am
> doing wrong?
The thing is that the parameter 'bar' is actually a dictionary object
so the right way of calling shuf is then
x,foo,bar = shuf(1,2,3,4,5,a=6,b=7,c=8)




More information about the Python-list mailing list