Re: forwarding *arg parameter

2006-11-07 Thread Tuomas
Steven D'Aprano wrote: > On Mon, 06 Nov 2006 13:03:55 +, Tuomas wrote: > > >>If you read the whole chain you find out what we were talking of. > > > I had already read the whole thread, and I've read it again in case I > missed something the first time, and I still have no idea why you thin

Re: forwarding *arg parameter

2006-11-06 Thread Steven D'Aprano
On Mon, 06 Nov 2006 13:03:55 +, Tuomas wrote: > If you read the whole chain you find out what we were talking of. I had already read the whole thread, and I've read it again in case I missed something the first time, and I still have no idea why you think you need to do this. You explain *wha

Re: forwarding *arg parameter

2006-11-06 Thread Tuomas
Steve Holden wrote: > Suppose you did actually want to do this you have chosen about the worst > possible way: the use of global variables to condition function > execution is a sure way to get into trouble. Consider if somebody else > want to use your function: they also have to set a global in

Re: forwarding *arg parameter

2006-11-06 Thread Steve Holden
Tuomas wrote: > Steven D'Aprano wrote: > >>On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote: >> >> >> >>>Thanks. My solution became: >>> >>> >>def flattern(arg): >>> >>>... result = [] >>>... for item in arg: >>>... if isinstance(item, (list, tuple)): >>>... result.

Re: forwarding *arg parameter

2006-11-06 Thread Tuomas
Steven D'Aprano wrote: > On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote: > > >>Thanks. My solution became: >> >> >>> def flattern(arg): >>... result = [] >>... for item in arg: >>... if isinstance(item, (list, tuple)): >>... result.extend(flattern(item)) >>...

Re: forwarding *arg parameter

2006-11-06 Thread Tuomas
Dennis Lee Bieber wrote: > On Sun, 05 Nov 2006 22:51:00 GMT, Tuomas <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > >>> >> >>I fylly agree with tis: "Typically, the responsibility should be on the >>CALLER, not the CALLED..". I just don't know how to unpack *arg for >>ca

Re: forwarding *arg parameter

2006-11-06 Thread Steven D'Aprano
On Sun, 05 Nov 2006 19:35:58 +, Tuomas wrote: > Thanks. My solution became: > > >>> def flattern(arg): > ... result = [] > ... for item in arg: > ... if isinstance(item, (list, tuple)): > ... result.extend(flattern(item)) > ... else: > ... resu

Re: forwarding *arg parameter

2006-11-05 Thread Tuomas
Dennis Lee Bieber wrote: > On Sun, 05 Nov 2006 17:42:30 GMT, Tuomas <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > >>I am looking a shorter way to do the above in the case: >> >>def g(*arg): >> return arg >> >>def f(*arg): >> return g(arg) >> >>How can g know if

Re: forwarding *arg parameter

2006-11-05 Thread Tuomas
Stargaming wrote: > Either you take one of the snippets here: > http://aspn.activestate.com/ASPN/search?query=flattenĀ§ion=PYTHONCKBK&type=Subsection > > > or just use arg[0] clever (as mentioned a few times in this thread). Thanks. My solution became: >>> def flattern(arg): ... result = [

Re: forwarding *arg parameter

2006-11-05 Thread Stargaming
Tuomas schrieb: > Tuomas wrote: > >> def g(*arg): >> return arg >> >> def f(*arg): >> return g(arg) >> >> How can g know if it is called directly with (('foo', 'bar'),) or via >> f with ('foo', 'bar'). I coud write in f: return g(arg[0], arg[1]) if >> I know the number of arguments, but

Re: forwarding *arg parameter

2006-11-05 Thread Tuomas
Tuomas wrote: > def g(*arg): > return arg > > def f(*arg): > return g(arg) > > How can g know if it is called directly with (('foo', 'bar'),) or via f > with ('foo', 'bar'). I coud write in f: return g(arg[0], arg[1]) if I > know the number of arguments, but what if I don't know that in

Re: forwarding *arg parameter

2006-11-05 Thread Tuomas
Steven D'Aprano wrote: > You could write something like this: > > def g(*arg): > # Detect the special case of a single tuple argument > if len(arg) == 1 and type(arg[0]) == tuple: > return arg[0] > else: > return arg > > but now tuple arguments are treated differently

Re: forwarding *arg parameter

2006-11-05 Thread Steven D'Aprano
On Sun, 05 Nov 2006 15:26:58 +, Tuomas wrote: > >>> def g(*arg): > ... return arg > ... > >>> g('foo', 'bar') > ('foo', 'bar') > >>> # seems reasonable The function g: - takes the arguments 'foo' and 'bar' - collects them in a tuple named 'arg' = ('foo', 'bar') - returns the tuple name

Re: forwarding *arg parameter

2006-11-05 Thread Stargaming
Tuomas schrieb: > >>> def g(*arg): > ... return arg > ... > >>> g('foo', 'bar') > ('foo', 'bar') > >>> # seems reasonable > ... > >>> g(g('foo', 'bar')) > (('foo', 'bar'),) > >>> # not so good, what g should return to get rid of the outer tuple > > TV Use the following then: >>> g(*g('fo

Re: forwarding *arg parameter

2006-11-05 Thread Tuomas
Diez B. Roggisch wrote: > Tuomas schrieb: > >> >>> def g(*arg): >> ... return arg >> ... >> >>> g('foo', 'bar') >> ('foo', 'bar') >> >>> # seems reasonable >> ... >> >>> g(g('foo', 'bar')) >> (('foo', 'bar'),) >> >>> # not so good, what g should return to get rid of the outer tuple > >

Re: forwarding *arg parameter

2006-11-05 Thread Diez B. Roggisch
Tuomas schrieb: > >>> def g(*arg): > ... return arg > ... > >>> g('foo', 'bar') > ('foo', 'bar') > >>> # seems reasonable > ... > >>> g(g('foo', 'bar')) > (('foo', 'bar'),) > >>> # not so good, what g should return to get rid of the outer tuple g(*g('foo', 'bar')) * and ** are the syme

forwarding *arg parameter

2006-11-05 Thread Tuomas
>>> def g(*arg): ... return arg ... >>> g('foo', 'bar') ('foo', 'bar') >>> # seems reasonable ... >>> g(g('foo', 'bar')) (('foo', 'bar'),) >>> # not so good, what g should return to get rid of the outer tuple TV -- http://mail.python.org/mailman/listinfo/python-list