Re: function argument dependent on another function argument?

2009-01-18 Thread Steven D'Aprano
On Sun, 18 Jan 2009 22:28:04 +, Steven D'Aprano wrote: > Built-ins rarely accept None as a sentinel, slice() being a conspicuous > exception. This is sometimes a nuisance when writing wrappers: > > def my_find(S, sub, start=None, end=None): > """Like string.find() only with pre-processing

Re: function argument dependent on another function argument?

2009-01-18 Thread Aaron Brady
On Jan 18, 12:02 pm, Rob Williscroft wrote: > Aaron Brady wrote > innews:582ef883-0176-4984-9521-6c1894636...@a26g2000prf.googlegroups.com > in comp.lang.python: > > > > > On Jan 18, 10:44 am, Rob Williscroft wrote: > >> Aaron Brady wrote > >> innews:6a10378f-addb-4d56-bc1b-0c382b3cb...@t26g2000

Re: function argument dependent on another function argument?

2009-01-18 Thread Aaron Brady
On Jan 18, 12:42 pm, andrew cooke wrote: > >     sentinel = object() > >     ... > > >     def foo(x, y=sentinel): > >       if y is sentinel: > >           y = self.a > > it just struck me you could also do: > >      def foo(self, x, *y_args) >        y = y_args[0] if y_args self.a > > which more

Re: function argument dependent on another function argument?

2009-01-18 Thread Paul Rubin
Steven D'Aprano writes: > Having said that, there are times where you need to pass None as a > legitimate argument and not as a sentinel. I don't think it's worth trying to figure out which those times are. The conclusion can be wrong, or can become wrong later because of some faraway change in

Re: function argument dependent on another function argument?

2009-01-18 Thread Steven D'Aprano
On Sun, 18 Jan 2009 07:36:53 -0800, Paul Rubin wrote: > Steven D'Aprano writes: >> def foo(self, x, y=None): >> if y is None: >> y = self.a >> >> I don't find that clumsy in the least. I find it perfectly readable and >> a standard idiom. > > That has the same problem as the earlier

Re: function argument dependent on another function argument?

2009-01-18 Thread andrew cooke
>     sentinel = object() >     ... > >     def foo(x, y=sentinel): >       if y is sentinel: >           y = self.a it just struck me you could also do: def foo(self, x, *y_args) y = y_args[0] if y_args self.a which more directly checks whether an argument was passed, but has the do

Re: function argument dependent on another function argument?

2009-01-18 Thread Rob Williscroft
Aaron Brady wrote in news:582ef883-0176-4984-9521-6c1894636...@a26g2000prf.googlegroups.com in comp.lang.python: > On Jan 18, 10:44 am, Rob Williscroft wrote: >> Aaron Brady wrote >> innews:6a10378f-addb-4d56-bc1b-0c382b3cb...@t26g2000prh > .googlegroups.com >> in comp.lang.python: >> >> > It

Re: function argument dependent on another function argument?

2009-01-18 Thread Aaron Brady
On Jan 18, 10:44 am, Rob Williscroft wrote: > Aaron Brady wrote > innews:6a10378f-addb-4d56-bc1b-0c382b3cb...@t26g2000prh.googlegroups.com > in comp.lang.python: > > > > > On Jan 18, 9:36 am, Paul Rubin wrote: > >> Steven D'Aprano writes: > >> > def foo(self, x, y=

Re: function argument dependent on another function argument?

2009-01-18 Thread Rob Williscroft
Aaron Brady wrote in news:6a10378f-addb-4d56-bc1b-0c382b3cb...@t26g2000prh.googlegroups.com in comp.lang.python: > On Jan 18, 9:36 am, Paul Rubin wrote: >> Steven D'Aprano writes: >> > def foo(self, x, y=None): >> >     if y is None: >> >         y = self.a >> >> >

Re: function argument dependent on another function argument?

2009-01-18 Thread Aaron Brady
On Jan 18, 9:36 am, Paul Rubin wrote: > Steven D'Aprano writes: > > def foo(self, x, y=None): > >     if y is None: > >         y = self.a > > > I don't find that clumsy in the least. I find it perfectly readable and a > > standard idiom. > > That has the same proble

Re: function argument dependent on another function argument?

2009-01-18 Thread Paul Rubin
Steven D'Aprano writes: > def foo(self, x, y=None): > if y is None: > y = self.a > > I don't find that clumsy in the least. I find it perfectly readable and a > standard idiom. That has the same problem as the earlier version. If the person passes None, they get self.a. I prefer:

Re: function argument dependent on another function argument?

2009-01-18 Thread Steven D'Aprano
On Sun, 18 Jan 2009 06:19:03 -0800, Reckoner wrote: > I would like to do: > > def foo(self,x,y=self.a) > > where the default value for y=self.a. Since this is not possible, I wind > up doing > > > def foo(self,x,y=None) > if not y: > y=self.a > > but that seems kind of clumsy. It's al

Re: function argument dependent on another function argument?

2009-01-18 Thread Aaron Brady
On Jan 18, 8:19 am, Reckoner wrote: > I  would like to do: > > def foo(self,x,y=self.a) > > where the default value for y=self.a. Since this is not possible, I > wind up doing > > def foo(self,x,y=None) >   if not y: >     y=self.a > > but that seems kind of clumsy. > > Is there a better way to do

function argument dependent on another function argument?

2009-01-18 Thread Reckoner
I would like to do: def foo(self,x,y=self.a) where the default value for y=self.a. Since this is not possible, I wind up doing def foo(self,x,y=None) if not y: y=self.a but that seems kind of clumsy. Is there a better way to do this? Thanks in advance -- http://mail.python.org/mailma